menu bar colors when enabled/disabled

  • 4 Replies
menu bar colors when enabled/disabled
« on: 09 August 2019, 10:44:44 »
I have a little problem with the menu bar.

I have created a menu

Code: [Select]
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:

Code: [Select]
if (event.key.code == sf::Keyboard::A)
else if (event.key.code == sf::Keyboard::S)

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?

Re: menu bar colors when enabled/disabled
« Reply #1 on: 09 August 2019, 14:07:32 »
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:


Re: menu bar colors when enabled/disabled
« Reply #2 on: 09 August 2019, 17:17:44 »
Can you provide MCVE (Minimal Complete Verifiable Example) for reproducing the behaviour? 



  • *****
  • 1625
    • View Profile
    • Texus's Blog
Re: menu bar colors when enabled/disabled
« Reply #3 on: 09 August 2019, 19:07:38 »
The color not being updated when disabling and enabling the widget has actually been fixed already. Try building the version from github:

is 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");
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?

Re: menu bar colors when enabled/disabled
« Reply #4 on: 10 August 2019, 16:26:52 »
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