From 52c820e7b06cb0675afac53593ba1cb5f59b446f Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 14 Jul 2015 09:09:52 -0600 Subject: [PATCH 1/3] Metrics: more details in popup stack (#272) --- imgui.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 75d831308..b0dde4bfe 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -12100,10 +12100,13 @@ void ImGui::ShowMetricsWindow(bool* opened) Funcs::NodeDrawList(g.RenderDrawLists[0][i], "DrawList"); ImGui::TreePop(); } - if (ImGui::TreeNode("Popups", "Opened Popups (%d)", g.OpenedPopupStack.Size)) + if (ImGui::TreeNode("Popups", "Opened Popups Stack (%d)", g.OpenedPopupStack.Size)) { for (int i = 0; i < g.OpenedPopupStack.Size; i++) - ImGui::BulletText("PopupID: %08x, Window: '%s'", g.OpenedPopupStack[i].PopupID, g.OpenedPopupStack[i].Window ? g.OpenedPopupStack[i].Window->Name : "NULL"); + { + ImGuiWindow* window = g.OpenedPopupStack[i].Window; + ImGui::BulletText("PopupID: %08x, Window: '%s'%s%s", g.OpenedPopupStack[i].PopupID, window ? window->Name : "NULL", window && (window->Flags & ImGuiWindowFlags_ChildWindow) ? " ChildWindow" : "", window && (window->Flags & ImGuiWindowFlags_ChildMenu) ? " ChildMenu" : ""); + } ImGui::TreePop(); } g.DisableHideTextAfterDoubleHash--; From 355cbf632664ddcdd8244d9568d5f9d9c3e5e566 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 14 Jul 2015 09:10:31 -0600 Subject: [PATCH 2/3] Examples: added tests for Combo box in sub-menu test and MenuItem in a normal window (#272) --- imgui.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index b0dde4bfe..64f2716bf 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -11705,6 +11705,17 @@ void ImGui::ShowTestWindow(bool* opened) ShowExampleMenuFile(); ImGui::EndPopup(); } + + ImGui::TextWrapped("Below we are testing adding menu items to a regular window. It's rather unusual but should work!"); + ImGui::Separator(); + ImGui::MenuItem("Menu item", "CTRL+M"); + if (ImGui::BeginMenu("Menu")) + { + ShowExampleMenuFile(); + ImGui::EndMenu(); + } + ImGui::Separator(); + ImGui::TreePop(); } @@ -12172,8 +12183,10 @@ static void ShowExampleMenuFile() ImGui::Text("Scrolling Text %d", i); ImGui::EndChild(); static float f = 0.5f; + static int n = 0; ImGui::SliderFloat("Value", &f, 0.0f, 1.0f); ImGui::InputFloat("Input", &f, 0.1f); + ImGui::Combo("Combo", &n, "Yes\0No\0Maybe\0\0"); ImGui::EndMenu(); } if (ImGui::BeginMenu("Colors")) From 8cfd963fda9be037afdb1e0d5834d99344713f87 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 14 Jul 2015 09:21:41 -0600 Subject: [PATCH 3/3] Popups: removed an apparently unnecessary test in CloseInactivePopups() that broke Combo boxes inside menus (#272) --- imgui.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 64f2716bf..c738b2d9e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3172,7 +3172,7 @@ static void CloseInactivePopups() if (g.OpenedPopupStack.empty()) return; - // When popups are stacked, clicking on a lower level popups puts focus back to it and close popups above it + // When popups are stacked, clicking on a lower level popups puts focus back to it and close popups above it. // Don't close our own child popup windows int n = 0; if (g.FocusedWindow) @@ -3184,21 +3184,17 @@ static void CloseInactivePopups() continue; IM_ASSERT((popup.Window->Flags & ImGuiWindowFlags_Popup) != 0); if (popup.Window->Flags & ImGuiWindowFlags_ChildWindow) - { - if (g.FocusedWindow->RootWindow != popup.Window->RootWindow) - break; - } - else - { - bool has_focus = false; - for (int m = n; m < g.OpenedPopupStack.Size && !has_focus; m++) - has_focus = (g.OpenedPopupStack[m].Window && g.OpenedPopupStack[m].Window->RootWindow == g.FocusedWindow->RootWindow); - if (!has_focus) - break; - } + continue; + + bool has_focus = false; + for (int m = n; m < g.OpenedPopupStack.Size && !has_focus; m++) + has_focus = (g.OpenedPopupStack[m].Window && g.OpenedPopupStack[m].Window->RootWindow == g.FocusedWindow->RootWindow); + if (!has_focus) + break; } } - g.OpenedPopupStack.resize(n); + if (n < g.OpenedPopupStack.Size) // This test is not required but it allows to set a useful breakpoint on the line below + g.OpenedPopupStack.resize(n); } static ImGuiWindow* GetFrontMostModalRootWindow()