ItemBox Item, getting addItem data within CreateWidgetItem

James259

18-03-2011 00:56:07

Hi,

I have been using example from this post to get to where I am now.
http://www.ogre3d.org/addonforums/viewtopic.php?f=17&t=10584
("small example only for view", post 5)

So far, seems to work nicely.
However, there is something that I really cannot see how to do.

From within "requestCreateWidgetItem(MyGUI::ItemBoxPtr _sender, MyGUI::WidgetPtr _item)" I need to get the value that was provided when I called ImageBox::addItem(value).
The main reason I need to do this is that I need to store a pointer to the created Widget(s) in an external object so that events that affect this Item can call in and update the Widget(s).

In "requestDrawItem(MyGUI::ItemBoxPtr _sender, MyGUI::WidgetPtr _item, const MyGUI::IBDrawItemInfo& _info)" the following is demonstrated (in the code in the linked post) which does what I need:
int data = *_sender->getItemDataAt<int>(_info.index);

Any suggestions? I am sure I am missing something obvious, just cannot see it.

Many Thanks.

James

James259

18-03-2011 01:02:00

Missed something.

I would also like to add the extra parameter (the name/lookup key/unique ID) onto the createWidget call that includes the int value supplied when calling addItem().

Altren

18-03-2011 07:09:44

I don't get it. You showed code that does what you need, so what's the problem then?

And about createWidget:
- it have optional widget name that you can use;
- you can use setUserString/getUserString to store string pairs (key and value);
- you can use setUserData/getUserData to store any data (there is Any class similar to boost::any that can hold instances of any type).

James259

19-03-2011 18:13:13

Hi Altren,

Sorry if I did not explain it clearly enough.

The example code I showed you is from the "requestDrawItem(MyGUI::ItemBoxPtr _sender, MyGUI::WidgetPtr _item, const MyGUI::IBDrawItemInfo& _info)" member.
This member has "const MyGUI::IBDrawItemInfo& _info" in its signature.

What I need is this in the "requestCreateWidgetItem(MyGUI::ItemBoxPtr _sender, MyGUI::WidgetPtr _item)" member but MyGUI::IBDrawItemInfo is not passed to this member and I do not know how to get it.

Does this make some sense now?

Cheers,

James

James259

20-03-2011 22:48:03

From within: requestCreateWidgetItem(MyGUI::ItemBoxPtr _sender, MyGUI::WidgetPtr _item)

would the following be safe to use to get the index of the newly added item?

int data = *_sender->getItemDataAt<int>(_sender.getItemCount()-1);


..or am I missing something very silly here that is much simpler?
All I am trying to do is access the integer value that I passed when calling itemBox->addItem(int), from inside the requestCreateWidgeItem() event.

James259

21-03-2011 18:10:34

Hi Altren,

I don't get it. You showed code that does what you need, so what's the problem then?

The example code I showed you is from the "requestDrawItem(MyGUI::ItemBoxPtr _sender, MyGUI::WidgetPtr _item, const MyGUI::IBDrawItemInfo& _info)" member.
This member has "const MyGUI::IBDrawItemInfo& _info" in its signature.

What I need is this in the "requestCreateWidgetItem(MyGUI::ItemBoxPtr _sender, MyGUI::WidgetPtr _item)" member but MyGUI::IBDrawItemInfo is not passed to this member and I do not know how to get it.


If you still don't understand the problem that I am describing, could you let me know so that I can describe it differently.

Cheers,

James

Altren

21-03-2011 20:24:01

Ah, my.name explained me what you need and what's the problem. You need your data in request, but the point is that this is some abstract widget, not bonded to any data. ItemBox doesn't create widget for each item - it create only for visible items. So this widget can be used for one item and after some actions for another. So, you never should use item specific data there. You should use that data in requestDrawItem. So create something that fit for all items and only in draw request fill it. If you have different widgets in different items you can, for example, create both and then hide those that you don't need.

James259

21-03-2011 22:15:33

Thank-you Altren, (and my.name)

I understand now why I could not do what I was trying to do.

I very much appreciate your time, and especially the extra effort you put in to help me in English.

Cheers,

James