Extending ItemListBox

If you found a bug in our library or on our website, please report it in this section. In this forum you can also make concrete suggestions or feature requests.

Moderators: CEGUI MVP, CEGUI Team

User avatar
Turtle
Not too shy to talk
Not too shy to talk
Posts: 24
Joined: Tue Nov 08, 2005 22:36

Extending ItemListBox

Postby Turtle » Wed Sep 01, 2010 21:15

Hi CE,

I'm in love with ItemListBox but for my own purposes I was after a bit of extra functionality. I added these and I was wondering if you would like them (in one form or another) for the main source.

I added the following properties:

"Orientation" (set to "Vertical" or "Horizontal") - Modifies the orientation of the listbox between vertical (like it is now) and horizontal.

"FixedItemSize" (a UVector2 value) - Overwrites the size of all ItemEntry items (as defined per ItemEntry by the "ContentSize" named area from the looknfeel) to your own preference. It takes a standard UVector2 string, ie: {{relative_width, offset_width},{relative_height, offset_height}}. If you only want to fix the width or hight and not both, set the other to {0,0}.

"MultiItemPerLine" (a bool value) - If this is set to Yes/True, then it will pack multiple ItemEntry items into each "row" for a vertical orientation, or each "column" for a horizontal orientation. Similar to how Windows Explorer works in "Icons" or "Thumbnails" view modes. This isn't really like a MultiColumnList, even if is sounds and in some ways looks like one.

This has so far meant updating CEGUIItemListbox.h/.cpp, CEGUIItemListboxProperties.h/.cpp and a small change in CEGUIScrolledItemListBase.cpp.

I originally faked some of this using regular lua, but it added a bit of overhead to what I was doing and using properties in a layout file is just so much nicer.

I'd also like to expand on the sorting so you can tell it to sort on properties other than the "text" value, as well as UserTextStrings, and to also have the option of sorting numbers as numbers rather than as strings.

A screen shot with a vertical list on the left, horizontal on the right, both with MultiItemPerLine turned on along with a FixedItemSize:
Image
(I need to get a more interesting screenshot.)

Cheers.

PS: Thanks for providing such a wonderful library :D . So many times I've gone to code something only to find that I can just modify or add to the .looknfeel and .scheme files.

User avatar
Jabberwocky
Quite a regular
Quite a regular
Posts: 86
Joined: Wed Oct 31, 2007 18:16
Location: Canada
Contact:

Re: Extending ItemListBox

Postby Jabberwocky » Thu Sep 02, 2010 07:16

Horizontal ItemListBoxes would be awesome.
The Salvation Prophecy
Space Combat. Planet Exploration. Strategic Domination.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Extending ItemListBox

Postby CrazyEddie » Thu Sep 02, 2010 09:13

Yeah, I think pretty much all these changes sound interesting, so I'm certainly for having such facilities rolled in to the CEGUI core ;)

Before submitting anything, you should definitely have read this page: http://www.cegui.org.uk/docs/current/devel.html in order that changes can be integrated quickly and cleanly, and without me getting all upset :lol:

CE

User avatar
Turtle
Not too shy to talk
Not too shy to talk
Posts: 24
Joined: Tue Nov 08, 2005 22:36

Re: Extending ItemListBox

Postby Turtle » Thu Sep 02, 2010 09:47

Thanks for the link. :) I'll modify my code to match the CEGUI formatting and give it a few more comments before I submit the patch.

Most probably will take me a day or two.

Cheers.

User avatar
Turtle
Not too shy to talk
Not too shy to talk
Posts: 24
Joined: Tue Nov 08, 2005 22:36

Re: Extending ItemListBox

Postby Turtle » Sat Sep 04, 2010 04:10

Hi CE,

I've cleaned up the code but I'm unable to logon to your mantis system with my forum account - do I need to be granted access to this?

Also, would you like a sample/demo app that shows some of the features? I could do one that uses Lua and drag and drop between ItemListboxes if you would like one.

Cheers.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Extending ItemListBox

Postby CrazyEddie » Sun Sep 05, 2010 09:26

Hmmm. Strange that mantis is not working for you, though it's not the first time I've had people tell me this. I looked up your user name on there but it does not exist, the entry there should automatically get added when you try and log on for the first time using your forum credentials. What error do you get?

I like the proposal of a new demo - especially a lua based one :)

If by the time you're done, we have not resolved the mantis log-in issue, you may send me the patch(es) via email, while we work to resolve that ;)

CE.

User avatar
Turtle
Not too shy to talk
Not too shy to talk
Posts: 24
Joined: Tue Nov 08, 2005 22:36

Re: Extending ItemListBox

Postby Turtle » Tue Nov 16, 2010 09:27

Hi CE,

Most probably will take me a day or two.
:oops:

I'm still working on this - it's been a bit slooow with work and stuff. (and most of the effort has been with the Sample.)

Are you adverse to me including some public domain graphics in the Sample? I'm looking at having three different windows within the single sample to show some of the things you could use it for - one with fantasy pixel art in an rpg "inventory" type system, one with "files and folders" like a simple Windows Explorer and a final window with lists of countries and tanks and the like for a strategy game kind of look.

Cheers.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Extending ItemListBox

Postby CrazyEddie » Sat Nov 20, 2010 14:38

Additional, free, assets for the samples is fine, though please include a reference to some place where we can verify it's status and also to include a credit in the docs :)

Cheers,

CE.

pw242
Just popping in
Just popping in
Posts: 6
Joined: Fri Apr 29, 2011 12:10

Re: Extending ItemListBox

Postby pw242 » Sat May 21, 2011 18:53

I wanted to sort a column as numbers, so I created a derived class from ListboxTextItem. I've had to resort to a dynamic_cast which I don't like, but it seems to do the job:

Code: Select all

class ListboxNumberItem : public ListboxTextItem
{
   int value;
public:
   ListboxNumberItem(int value, CEGUI::uint item_id = 0, void* item_data = 0, bool disabled = false, bool auto_delete = true);
   void setText(int value);
   virtual ~ListboxNumberItem(void) {}
   virtual bool operator<(const ListboxItem &rhs) const;
   virtual bool operator>(const ListboxItem &rhs) const;
};

ListboxNumberItem::ListboxNumberItem(int value, uint item_id, void* item_data, bool disabled, bool auto_delete) :
      ListboxTextItem(boost::lexical_cast<std::string>(value), item_id, item_data, disabled, auto_delete),
      value(value)
   {
   }
   void ListboxNumberItem::setText(int value)
   {
      this->value = value;
      ListboxItem::setText(boost::lexical_cast<std::string>(value));
   }
   bool ListboxNumberItem::operator<(const ListboxItem &rhs) const
   {
      const ListboxNumberItem *number=dynamic_cast<const ListboxNumberItem*>(&rhs);
      if (number)
         return value<number->value;
      return ListboxItem::operator<(rhs);
   }
   bool ListboxNumberItem::operator>(const ListboxItem &rhs) const
   {
      const ListboxNumberItem *number=dynamic_cast<const ListboxNumberItem*>(&rhs);
      if (number)
         return value>number->value;
      return ListboxItem::operator>(rhs);
   }


Has anyone got a nicer way of doing this?

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Extending ItemListBox

Postby CrazyEddie » Sun May 22, 2011 09:05

The use of the dynamic_cast in situations such as this is technically correct. Just because C++ is strongly statically typed does not mean that there will not be situations where you need to identify types at runtime. IMO the solution is fine, the alternatives would surely involve making assumptions about types and then suffering the consequences.

CE.


Return to “Bug Reports, Suggestions, Feature Requests”

Who is online

Users browsing this forum: Bing [Bot] and 3 guests