[SOLVED][0.7] connect menu item

Started by cpl.bator, 03 December 2014, 14:42:19

cpl.bator

Hi , i've problem to understand how to connect menu item with , i try this way :

auto menu = tgui::MenuBar::create(THEME);
    menu->setSize(mWindow.getSize().x, 22);
    menu->addMenu("Fichier");
    menu->addMenuItem("Fichier", "Importer image");
    menu->addMenuItem("Fichier", "Enregistrer");
    menu->addMenuItem("Fichier", "Enregistrer sous...");
    menu->addMenuItem("Fichier", "Quitter");


menu->connect("MenuItemClicked", my_func,... and what ? ...


the func has been called , but i cannot retrieve the item selected , it's big problem for an application ^^
Thanks.

texus

There are two ways to do it, depending on which compilers you want to support.

The first way will only work on the latest compilers (not with VS), but it the nicest one to use.

void my_func(sf::String param); // param == "Quitter", param could also be an std::string if wanted
menu->connect("MenuItemClicked", my_func);

void my_func2(std::vector<sf::String> param); // param[0] = "Fichier", param[1] = "Quitter"
menu->connect("MenuItemClicked", my_func2);


The second method is the legacy method which uses the Callback class from v0.6.

void my_func(const tgui::Callback& c); // c.text == "Quitter"
menu->connectEx("MenuItemClicked", my_func2);


The information for which parameters can be used for which widget can always be found in the Documentation.

cpl.bator

Thank you, only third solution work for me ( gcc 4.7.2 with mingw on win7 )
Very simple to use by this way too. The examples are poor for the potential of this lib.

@++

texus

Quoteonly third solution work for me ( gcc 4.7.2 with mingw on win7 )
Interesting. I though gcc 4.7 was the minimum compiler that my code supported. So either the MinGW port just isn't as good as it should be, or the minimum support is gcc 4.8. I guess I will have to look into that.

The only limitation of the third method is that you cannot have multiple menu items with the same name in different menus. But usually that isn't a problem.

QuoteThe examples are poor for the potential of this lib.
Feel free to write your own examples and send them to me :)