Page 1 of 1
How can I populate a Listbox in LUA?
Posted: Wed Mar 08, 2006 15:57
by Trentin
I'm trying to populate a listbox in LUA but I'm stuck on how I should create the ListboxItem's so I can insert them.
Here's what little I have so far:
Code: Select all
local pScoreList = tolua.cast(gWindowMgr:getWindow("lbScores"), "CEGUI::Listbox");
local listItem = gWindowMgr:createWindow("WindowsLook/ListboxItem","item1");
pScoreList:addItem(listItem);
The second line does not work at all, there's no factory for that type. Do I need one? Or am I way off?
Posted: Wed Mar 08, 2006 21:40
by lindquist
Listbox items are not widgets and therefore you dont use the WindowManager to create the items.
Use something like this:
Code: Select all
local function createItem(list, txt)
local item = CEGUI.createListboxTextItem(txt)
item:setTextColours(CEGUI.colour(0,0,0,1))
item:setSelectionBrushImage("WindowsLook", "Background");
item:setSelectionColours(CEGUI.colour(0.2,0.2,1,1))
list:addItem(item)
end
local pScoreList = tolua.cast(gWindowMgr:getWindow("lbScores"), "CEGUI::Listbox");
createItem(pScoreList, "Item1")
createItem(pScoreList, "Item2")
createItem(pScoreList, "Item3")
Posted: Thu Mar 09, 2006 17:19
by Trentin
Thanks! I'm able to create and insert the list items now
Unfortunately these lines are giving me problems:
Code: Select all
item:setTextColours(CEGUI.colour(0,0,0,1))
item:setSelectionColours(CEGUI.colour(0.2,0.2,1,1))The error for those lines is:
Code: Select all
error in function 'new'.
argument #1 is 'class CEGUI::colour'; 'CEGUI::MCLGridRef' expected.Looks like it's just not finding the right overloaded function...
Update: And here's the solution
Code: Select all
-- create temp colour objects
local textColour = CEGUI.colour:new(0,0,0,1);
local selColour = CEGUI.colour:new(0.2,0.2,1,1);
item:setTextColours(textColour);
item:setSelectionBrushImage("WindowsLook", "Background");
item:setSelectionColours(selColour);
Posted: Thu Mar 09, 2006 21:59
by lindquist
unless you're freeing 'textColour' and 'selColour' manually you're making memory leaks.
Use 'new_local' to avoid that
Posted: Sat Mar 11, 2006 00:39
by Trentin
Thanks again! I would have never noticed that.