From c263961f07fff4615c6390f449e0d4253bee8f89 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 4 Aug 2016 10:41:33 +0200 Subject: [PATCH] Nav: Menu: Allow PadDown to open a menu from a menu bar, PadRight from a menu (#323, #126) --- imgui.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 52cab7054f20..07ab3908fe66 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9754,14 +9754,25 @@ bool ImGui::BeginMenu(const char* label, bool enabled) want_close = menu_is_open; want_open = !menu_is_open; } + if (g.NavId == id && g.NavMoveRequest && g.NavMoveDir == ImGuiNavDir_Right) // Nav-Right to open + { + want_open = true; + g.NavMoveRequest = false; + } } - else if (menu_is_open && pressed && menuset_is_open) // menu-bar: click open menu to close + else if (menu_is_open && pressed && menuset_is_open) // Menu bar: click an open menu again to close it { want_close = true; want_open = menu_is_open = false; } - else if (pressed || (hovered && menuset_is_open && !menu_is_open)) // menu-bar: first click to open, then hover to open others + else if (pressed || (hovered && menuset_is_open && !menu_is_open)) // Menu bar: click to open a first menu, then hover to open others + want_open = true; + else if (g.NavId == id && g.NavMoveRequest && g.NavMoveDir == ImGuiNavDir_Down) // Menu bar: Nav-Down to open + { + g.NavMoveRequest = false; want_open = true; + } + if (!enabled) // explicitly close if an open menu becomes disabled, facilitate users code a lot in pattern such as 'if (BeginMenu("options", has_object)) { ..use object.. }' want_close = true; if (want_close && IsPopupOpen(id))