menu bar colors when enabled/disabled

Started by roccio, 09 August 2019, 10:44:44

roccio

Hi,
I have a little problem with the menu bar.

I have created a menu


auto menu = tgui::MenuBar::create();
menu->getRenderer()->setTextColorDisabled(sf::Color(229*1, 131*0, 4*0));


and then in the main window loop I use two keypresses for enable or disable the menu:


if (event.key.code == sf::Keyboard::A)
    gui.get<tgui::MenuBar>("MenuBar")->setEnabled(false);
else if (event.key.code == sf::Keyboard::S)
    gui.get<tgui::MenuBar>("MenuBar")->setEnabled(true);


The menu is correctly enabled/disabled by the two events, but the problem is that when disabled the menu ites are rendered in RED, but when I reenable the menu the items are again in red untill I move the mouse over them.

Is there something I miss to get the items of the correct color?

roccio

Another question: is there a way to change the menu item text?
I need it to show if an item is selected or not (adding a character in front like this:

  menuItem0
  menuItem1
*menuItem2
  menuItem3

Kvaz1r

Can you provide MCVE (Minimal Complete Verifiable Example) for reproducing the behaviour? 

texus

The color not being updated when disabling and enabling the widget has actually been fixed already. Try building the version from github: https://github.com/texus/TGUI

Quoteis there a way to change the menu item text?
This is currently not possible. You will have to remove the items and add them again (either all menus or just the menu in which an item needs to change by calling removeMenuItem for each item).
If you want to have spaces in front of all items and only have the star in front of one item then you need to update multiple items anyway and recreating the menu might not be such a bad solution.

If it were possible to change an individual item text, how would you want the API to look like?
Code (cpp) Select
menuBar->setMenuItemText("menu", "menuItem2", "> menuItem2");
menuBar->setMenuItemText("menu", "> menuItem2", "menuItem2");

or
Code (cpp) Select
menuBar->setMenuItemText("menu", 2, "> menuItem2"); // 2 being the index
menuBar->setMenuItemText("menu", 2, "menuItem2");


The first one looks nicer to me, but for the second one you don't need to care what the current text is to change it. On the other hand, the first one would be easier to extend to sub-menus.

Purely as information on how to improve the MenuBar in the far future, would you still need this feature if it were possible to display an image in front of menu items (either a unique image per item or just a single "selected" image that is used in front of any item that gets selected)? Or if there were optional checkboxes in front of items?

roccio

Thanks fot the help, will try your solution to change the text.

Fot the future I like most the first solution as it is more clear and more consistent with the other functions.
The image would be a great update, but better would be to have a checkbox.

Best regards