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

Weird keyboard nav with multiple BeginMenu calls #3223

Closed
u3shit opened this issue May 11, 2020 · 1 comment
Closed

Weird keyboard nav with multiple BeginMenu calls #3223

u3shit opened this issue May 11, 2020 · 1 comment
Labels
menus menu bars, menu items nav keyboard/gamepad navigation

Comments

@u3shit
Copy link
Contributor

u3shit commented May 11, 2020

Version/Branch of Dear ImGui:

Version: 1.77
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_glew.cpp + imgui_impl_opengl3.cpp
Operating System: Linux

My Issue/Question:

In my program, I can call BeginMainMenuBar and BeginMenu multiple times, and the menu items I add are automatically combined. Neat! But the keyboard navigation is working weird in this case. In the example below I add 4 menu items in two different locations. If I open the menu and start pressing the down button, the selection goes to a, b then it wraps back to a. If I press up, I get to d and actually only pressing the up button I can go through the whole menu, but not in the other direction. Also if I press down while d is selected, nothing happens.
The comment in imgui.h says "Use BeginMenu() to create a menu. You can call BeginMenu() multiple time with the same identifier to append more items to it." so I suppose this is a supported operation, and it works fine with mouse.

Screenshots/Video

foo

Standalone, minimal, complete and verifiable example:

if (ImGui::BeginMainMenuBar())
{
  if (ImGui::BeginMenu("Menu"))
  {
    ImGui::MenuItem("a");
    ImGui::MenuItem("b");
    ImGui::EndMenu();
  }
  ImGui::EndMainMenuBar();
}

if (ImGui::BeginMainMenuBar())
{
  if (ImGui::BeginMenu("Menu"))
  {
    ImGui::MenuItem("c");
    ImGui::MenuItem("d");
    ImGui::EndMenu();
  }
  ImGui::EndMainMenuBar();
}
@ocornut ocornut added menus menu bars, menu items nav keyboard/gamepad navigation labels May 11, 2020
ocornut pushed a commit that referenced this issue May 11, 2020
…multiple appending calls to BeginMenu()/EndMenu() or BeginPopup/EndPopup(). (#3223, #1207)

First call to EndPopup() called NavRequestTryWrapWindow() which performed wrap-around operation while we were not done composing menu. This resulted in navigation wrapping around to first item.
Since wrap-around operation is only valid in last call to EndPopup() and there is no way to know which call is last - this operation is delayed to the end of the frame.
@ocornut
Copy link
Owner

ocornut commented May 11, 2020

Thanks for reporting.
Should now fixed by a6f4b0f courtesy of @rokups (also added a regression test for it)

@ocornut ocornut closed this as completed May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
menus menu bars, menu items nav keyboard/gamepad navigation
Projects
None yet
Development

No branches or pull requests

2 participants