[Layout File]How to create delegates?

arkdemon

29-03-2014 09:14:56

Hello everyone. I am new to the forum and to MyGUI. I know how to create delegates for widgets we create in our code but I do not know how to create delegates for the widgets created from a layout file. Can someone tell me how we can do that?
Thank you for your help.

PS:
I want to do this:

exit->eventMouseButtonClick = MyGUI::newDelegate(quit);

but for the widgets inside a layout file.
Currently I can only do that:
MyGUI::Button* exit = mGUI->createWidget<MyGUI::Button>("Button", 0, 25, 100, 26, MyGUI::Align::Center, "Main");
exit->setCaption("Exit");
exit->eventMouseButtonClick = MyGUI::newDelegate(quit);


Thanks for your help!

Altren

29-03-2014 12:10:58

You should use eventAddUserString
/** Event : Multidelegate. UserString was added from layout.\n
signature : void method(MyGUI::Widget* _widget, const std::string& _key, const std::string& _value)
@param _widget Widget that got new UserString.
@param _key UserString key.
@param _key UserString value.
@note Happens only when UserString was loaded from layout, but not when it was added in code.
*/

// before loading layout
LayoutManager::getInstance().eventAddUserString += newDelegate(userStringLoaded);

void userStringLoaded(MyGUI::Widget* _widget, const std::string& _key, const std::string& _value)
{
if (_key == "event") // or whatever key you want
{
_widget->eventMouseButtonClick = MyGUI::newDelegate(/*select function based on _value*/);
}
}