How can I populate a Listbox in LUA?

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

User avatar
Trentin
Not too shy to talk
Not too shy to talk
Posts: 27
Joined: Tue Nov 22, 2005 21:25
Contact:

How can I populate a Listbox in LUA?

Postby Trentin » Wed Mar 08, 2006 15:57

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?

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Postby lindquist » Wed Mar 08, 2006 21:40

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")

User avatar
Trentin
Not too shy to talk
Not too shy to talk
Posts: 27
Joined: Tue Nov 22, 2005 21:25
Contact:

Postby Trentin » Thu Mar 09, 2006 17:19

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);

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Postby lindquist » Thu Mar 09, 2006 21:59

unless you're freeing 'textColour' and 'selColour' manually you're making memory leaks.

Use 'new_local' to avoid that

User avatar
Trentin
Not too shy to talk
Not too shy to talk
Posts: 27
Joined: Tue Nov 22, 2005 21:25
Contact:

Postby Trentin » Sat Mar 11, 2006 00:39

Thanks again! I would have never noticed that.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 32 guests