Page 1 of 1

Extending ItemListBox

Posted: Wed Sep 01, 2010 21:15
by Turtle
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.

Re: Extending ItemListBox

Posted: Thu Sep 02, 2010 07:16
by Jabberwocky
Horizontal ItemListBoxes would be awesome.

Re: Extending ItemListBox

Posted: Thu Sep 02, 2010 09:13
by CrazyEddie
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

Re: Extending ItemListBox

Posted: Thu Sep 02, 2010 09:47
by Turtle
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.

Re: Extending ItemListBox

Posted: Sat Sep 04, 2010 04:10
by Turtle
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.

Re: Extending ItemListBox

Posted: Sun Sep 05, 2010 09:26
by CrazyEddie
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.

Re: Extending ItemListBox

Posted: Tue Nov 16, 2010 09:27
by Turtle
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.

Re: Extending ItemListBox

Posted: Sat Nov 20, 2010 14:38
by CrazyEddie
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.

Re: Extending ItemListBox

Posted: Sat May 21, 2011 18:53
by pw242
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?

Re: Extending ItemListBox

Posted: Sun May 22, 2011 09:05
by CrazyEddie
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.