Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MenuItem and the "selected" parameter #4128

Closed
matte-ek opened this issue May 11, 2021 · 1 comment
Closed

MenuItem and the "selected" parameter #4128

matte-ek opened this issue May 11, 2021 · 1 comment
Labels
menus menu bars, menu items

Comments

@matte-ek
Copy link

Version: Dear ImGui 1.83 WIP (18209)
Branch: docking

Hi, the "MenuItem" function currently has an "selected" parameter:
bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected, bool enabled)

However, this parameter will be ignored if it's in a horizontal layout. The reason for this is because it will always pass "false" to the Selectable().

Using the following code:

if (ImGui::BeginMenuBar()) {
  if (ImGui::MenuItem("Move", nullptr, Globals::SelectedGizmoMovementType == GizmoMovementType::Move, inLevelViewport)) {
    Editor::Gui::Globals::SelectedGizmoMovementType = Editor::Gui::GizmoMovementType::Move;
  }
  
  if (ImGui::MenuItem("Rotate", nullptr, Globals::SelectedGizmoMovementType == GizmoMovementType::Rotate, inLevelViewport)) {
    Editor::Gui::Globals::SelectedGizmoMovementType = Editor::Gui::GizmoMovementType::Rotate;
  }
  
  if (ImGui::MenuItem( Scale", nullptr, Globals::SelectedGizmoMovementType == GizmoMovementType::Scale, inLevelViewport)) {
    Editor::Gui::Globals::SelectedGizmoMovementType = GizmoMovementType::Scale;
  }

Will result in:
image

Instead of the results I want to achieve (This was done by passing the "selected" argument to Selectable() instead.)
image

My question is if this is how it's supposed to work? Should I use something else instead? I would also like to point out the following comment in the MenuItem() code as it may be useful or explain things.

// Mimic the exact layout spacing of BeginMenu() to allow MenuItem() inside a menu bar, which is a little misleading but may be useful
// Note that in this situation we render neither the shortcut neither the selected tick mark

Regards

@ocornut ocornut added the menus menu bars, menu items label May 13, 2021
ocornut added a commit that referenced this issue May 20, 2021
@ocornut
Copy link
Owner

ocornut commented May 20, 2021

Hello,

I think this sort of use may be confusing but I see no harm in adding the change you suggested. Added now.
However it is possible in the future that we would change the look for it to use a check-mark.

(Note that you could easily simply call Selectable() with the right flags yourself)

Thank you!

@ocornut ocornut closed this as completed May 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
menus menu bars, menu items
Projects
None yet
Development

No branches or pull requests

2 participants