Skip to content

Commit

Permalink
Menus, Nav: Fixed not being able to close a menu with Left arrow when…
Browse files Browse the repository at this point in the history
… parent is not a popup. (#5730)
  • Loading branch information
ocornut committed Sep 29, 2022
1 parent 9f6aae3 commit 0749453
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
5 changes: 3 additions & 2 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ Other Changes:
towards a sub-menu. (#2517, #5614). [@rokups]
- Menus: Fixed gaps in closing logic which would make child-menu erroneously close when crossing
the gap between a menu item inside a window and a child-menu in a secondary viewport. (#5614)
- Menus, Nav: Fixed keyboard/gamepad navigation occasionally erroneously landing on menu-item in
parent when the parent is not a popup. (#5730)
- Menus, Nav: Fixed keyboard/gamepad navigation occasionally erroneously landing on menu-item
in parent window when the parent is not a popup. (#5730)
- Menus, Nav: Fixed not being able to close a menu with Left arrow when parent is not a popup. (#5730)
- Menus, Nav: Fixed using left/right navigation when appending to an existing menu (multiple
BeginMenu() call with same names). (#1207)
- Nav: Fixed moving/resizing window with gamepad or keyboard when running at very high framerate.
Expand Down
14 changes: 6 additions & 8 deletions imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7177,21 +7177,19 @@ bool ImGui::BeginMenu(const char* label, bool enabled)

void ImGui::EndMenu()
{
// Nav: When a left move request _within our child menu_ failed, close ourselves (the _parent_ menu).
// A menu doesn't close itself because EndMenuBar() wants to catch the last Left<>Right inputs.
// However, it means that with the current code, a BeginMenu() from outside another menu or a menu-bar won't be closable with the Left direction.
// FIXME: This doesn't work if the parent BeginMenu() is not on a menu.
// Nav: When a left move request our menu failed, close ourselves.
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
IM_ASSERT(window->Flags & ImGuiWindowFlags_Popup); // Mismatched BeginMenu()/EndMenu() calls

ImGuiWindow* parent_window = window->ParentWindow; // Should always be != NULL is we passed assert.
if (window->BeginCount == window->BeginCountPreviousFrame)
if (g.NavMoveDir == ImGuiDir_Left && NavMoveRequestButNoResultYet() && window->DC.LayoutType == ImGuiLayoutType_Vertical)
if (g.NavWindow && (g.NavWindow->RootWindowForNav->Flags & ImGuiWindowFlags_Popup) && g.NavWindow->RootWindowForNav->ParentWindow == window)
if (g.NavMoveDir == ImGuiDir_Left && NavMoveRequestButNoResultYet())
if (g.NavWindow && (g.NavWindow->RootWindowForNav == window) && parent_window->DC.LayoutType == ImGuiLayoutType_Vertical)
{
ClosePopupToLevel(g.BeginPopupStack.Size, true);
ClosePopupToLevel(g.BeginPopupStack.Size - 1, true);
NavMoveRequestCancel();
}

EndPopup();
}

Expand Down

0 comments on commit 0749453

Please sign in to comment.