From 51fcef0c21b9c05547370d02513406a196a739d6 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 6 Sep 2017 19:31:50 +0200 Subject: [PATCH] BeginCombo() tweaks, merged from Navigation branch. --- imgui.cpp | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index bb313abb6..acca6ed0d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7020,7 +7020,7 @@ bool ImGui::DragFloat(const char* label, float* v, float v_speed, float v_min, f // Tabbing or CTRL-clicking on Drag turns it into an input box bool start_text_input = false; const bool tab_focus_requested = FocusableItemRegister(window, id); - if (tab_focus_requested || (hovered && (g.IO.MouseClicked[0] | g.IO.MouseDoubleClicked[0]))) + if (tab_focus_requested || (hovered && (g.IO.MouseClicked[0] || g.IO.MouseDoubleClicked[0]))) { SetActiveID(id, window); FocusWindow(window); @@ -8599,25 +8599,31 @@ bool ImGui::BeginCombo(const char* label, const char* preview_value, float popup if (label_size.x > 0) RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); + bool popup_toggled = false; if (hovered) { SetHoveredID(id); if (g.IO.MouseClicked[0]) { ClearActiveID(); - if (IsPopupOpen(id)) - { - ClosePopup(id); - } - else - { - FocusWindow(window); - OpenPopup(label); - } + popup_toggled = true; } } + if (popup_toggled) + { + if (popup_open) + { + ClosePopup(id); + } + else + { + FocusWindow(window); + OpenPopupEx(id, false); + } + popup_open = !popup_open; + } - if (!IsPopupOpen(id)) + if (!popup_open) return false; float popup_y1 = frame_bb.Max.y; @@ -9054,7 +9060,10 @@ bool ImGui::BeginMenu(const char* label, bool enabled) 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 + { 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))