Listbox doesn't draw added ListboxTextItems

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

some_name
Just popping in
Just popping in
Posts: 15
Joined: Sat Mar 10, 2007 00:12

Listbox doesn't draw added ListboxTextItems

Postby some_name » Sun Apr 15, 2007 05:38

I'm trying to learn CEGUI, but I'm having a hard time, because all the documentation is of the hands-on code kind, and there isn't really any documentation on how all the pieces are supposed to fit together.

I have a layout that's loaded from a .layout file. It contains a TaharezLook/Listbox class. I want to add text items to this listbox (based on listing files in a directory).

However, I believe I'm doing the right thing, but I can't get the list box to actually draw the items I add.

Here's the function I call to add text items:

Code: Select all

void AddListboxItem(char const *name, char const *item)
{
  static int itemId;
  WidgetMap::iterator ptr = widgets_.find(name);
  if (ptr == widgets_.end()) return;
  CEGUI::String const &s = (*ptr).second->getType();
  if ((*ptr).second->getType() != CEGUI::String("TaharezLook/Listbox")) return;
  static_cast<CEGUI::Listbox *>((*ptr).second)->addItem(new CEGUI::ListboxTextItem(item, ++itemId));
  static_cast<CEGUI::Listbox *>((*ptr).second)->handleUpdatedItemData();
}


I understand that handleUpdatedItemData() is not needed, but I added it in a fit of desperation.

Here's the XML I use to create the listbox:

Code: Select all

      <Window Type="TaharezLook/Listbox" Name="LevelNameSelection">
        <Property Name="UnifiedPosition" Value="{{0.05,0},{0.20,0}}" />
        <Property Name="UnifiedSize" Value="{{0.9,0},{0.65,0}}" />
        <Property Name="Text" Value="Level To Edit" />
        <Property Name="SortEnabled" Value="True" />
        <Property Name="MultiselectEnabled" Value="False" />
        <Property Name="VertScrollbarAlwaysShown" Value="True" />
      </Window>


What am I doing wrong? What do I need to check?

User avatar
Levia
Quite a regular
Quite a regular
Posts: 83
Joined: Mon May 22, 2006 18:25
Location: Bergen op zoom, The Netherlands
Contact:

Postby Levia » Sun Apr 15, 2007 07:41

Right. This is..some odd code you got there. Let me just rewrite your function:

Code: Select all

void AddListboxItem(char const *name, char const *item)
{
  CEGUI::Listbox * lb = static_cast<CEGUI::Listbox*>(CEGUI::WindowManager::getSingletonPtr()->getWindow("LevelNameSelection"));
  lb->addItem(new CEGUI::ListboxTextItem("Hi there!"));
  //lb->addItem(new CEGUI::ListboxTextItem(item));
}

You can simply get a window by its name through the windowmanager, get used to that :)
You dont have to assign a ID for a item.
Image
Image

some_name
Just popping in
Just popping in
Posts: 15
Joined: Sat Mar 10, 2007 00:12

Postby some_name » Sun Apr 15, 2007 16:24

I'm sure there's something crazy in my code, as I'm trying to learn this GUI toolkit without any kind of overview to guide me.

As for the code:

widgets_ is the list of widgets that I actually want to allow control of.

Testing for the right type is necessary to avoid crashing in the case of wrong usage (this is driven from a script).

So, unfortunately, your re-write doesn't achieve the greater goals of the code of robustness and security.

I added the itemId when I couldn't get the items to show up, but it didn't help. However, it's interesting that you say the ID is not needed, because the documentation for ListboxTextItem says exactly this about the constructor:
base class constructor

It's kind of hard to derive the usage of that parameter from that :-)

However, even if I temporarily re-write the function using your code, nothing shows up in the listbox on screen. I'm using the default Ogre 3D renderer, btw, and edit boxes, buttons, static text and frame windows work fine.

Where should I look?

some_name
Just popping in
Just popping in
Posts: 15
Joined: Sat Mar 10, 2007 00:12

Postby some_name » Sun Apr 15, 2007 17:27

I now have the selection squared away, too. The selection brush on the item was needed, even though I set the selection colors.

User avatar
Levia
Quite a regular
Quite a regular
Posts: 83
Joined: Mon May 22, 2006 18:25
Location: Bergen op zoom, The Netherlands
Contact:

Postby Levia » Sun Apr 15, 2007 17:31

Im sorry, I didnt knew that list was use for security purposes, same goes for the type check. They should be alright :)

As for the item, try ensureItemIsVisible function in the listbox class.

Edit: Wait, I dont get that last reply. Does your item work now?
Image

Image

some_name
Just popping in
Just popping in
Posts: 15
Joined: Sat Mar 10, 2007 00:12

Postby some_name » Mon Apr 16, 2007 01:51

Yes, my list works now. Thanks for helping!


Return to “Help”

Who is online

Users browsing this forum: No registered users and 14 guests