something about EnumeratorWidgetPtr

planB

04-09-2010 10:54:22

thanks to Altren, i knows the function about MyGUI::EnumeratorWidgetPtr getEnumerator().
but when i use it like below, it does not work.

MyGUI::EnumeratorWidgetPtr enumitr=mMainWidget->getEnumerator();
while (enumitr.next())
{
MyGUI::WidgetPtr temp=enumit.current();
if (temp->getTypeName()=="Button")
{
temp->eventMouseButtonClick=MyGUI::newDelegate(this,&MainState::notifyMouseButtonClick);
}
}

when i click the button load from a layout file, it didn't implement the notifyMouseButtonClick event.
wht's wrong about this?

Altren

04-09-2010 11:38:12

Try next code:

MyGUI::EnumeratorWidgetPtr enumitr=mMainWidget->getEnumerator();
while (enumitr.next())
{
if (enumit->isType<MyGUI::Button>())
{
enumit->eventMouseButtonClick=MyGUI::newDelegate(this,&MainState::notifyMouseButtonClick);
}
}
Main change is isType<MyGUI::Button>() instead of strings comparison. Also removed your temp, just to make code better.

planB

04-09-2010 12:18:56

tks, but it still doesn't work .

when i debug to the while loop, i found that the enumitr only get one result and then pass the loop.
that mean it didn't get all children of the mMainWidget?

i initialise the layout with the baselayout class and the mMainWidget point to the "_main" window.

class MainState : public wraps::BaseLayout

initialise("MainPanel.layout");

MyGUI::EnumeratorWidgetPtr enumitr=mainwindow->getEnumerator();
while (enumitr.next())
{
//MyGUI::WidgetPtr temp=enumit.current();
if (enumit->isType<MyGUI::Button>())
{
enumit->eventMouseButtonClick=MyGUI::newDelegate(this,&MainState::notifyMouseButtonClick);
}
}

Altren

04-09-2010 12:32:57

Probably mainwindow have one child and it have many subchilds. Show me your layout or check your widgets hierarchy.

planB

04-09-2010 14:08:30

yes, you are right.

my maipanel.layout is too long, it's layout mainly like below,

window
tab
TabItem1
wighet
wighet
.......
TabItem2
wighet
wighet
.......
TabItem3
wighet
wighet
.......
.........


so, shouid the getEnumerator() only be used by TabItem seperately?
is there a more simple way to get all one type wights (include subchild wighet) in this layout?

Altren

04-09-2010 20:20:19

Recursion through all childs and their childs.

planB

05-09-2010 15:00:03

there is a function findwighet(), if we don't inherit from baselayout, we should use the findwighet() to assign the wighet by name.

so can it gothrough all the wighet include subchild?

Altren

05-09-2010 18:19:49

You can use getEnumerator for doing that, findWidget can find only one widget and only by name, not by type.
Here's example how you can go through all widgets and assign delegate for buttons:
voin assignDelegateToChildButtons(MyGUI::Widget* _widget)
{
MyGUI::EnumeratorWidgetPtr enumitr = _widget->getEnumerator();
while (enumitr.next())
{
if (enumitr->isType<MyGUI::Button>())
{
enumitr->eventMouseButtonClick=MyGUI::newDelegate(this,&MainState::notifyMouseButtonClick);
assignDelegateToChildButtons(enumitr.current());
}
}
}

And somewhere after loadin layout:
assignDelegateToChildButtons(myRootWidget);