[SOLVED][0.7] connect menu item
« on: 03 December 2014, 14:42:19 »
Hi , i've problem to understand how to connect menu item with , i try this way :

Code: [Select]
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.
« Last Edit: 03 December 2014, 16:30:35 by cpl.bator »

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: [0.7] connect menu item
« Reply #1 on: 03 December 2014, 15:07:36 »
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.
Code: [Select]
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.
Code: [Select]
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.

Re: [0.7] connect menu item
« Reply #2 on: 03 December 2014, 15:15:26 »
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

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: [0.7] connect menu item
« Reply #3 on: 03 December 2014, 15:22:41 »
Quote
only 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.

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