From 7c4be0a000abfc6645f56f654794473d5d358940 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 16 Nov 2017 13:11:16 +0100 Subject: [PATCH] Internals: Added BringWindowToFront(), BringWindowToBack() helpers. --- imgui.cpp | 43 ++++++++++++++++++++++++++++++++----------- imgui_internal.h | 2 ++ 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 088012bb..6d5b6bc9 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4793,7 +4793,35 @@ void ImGui::Scrollbar(ImGuiLayoutType direction) window->DrawList->AddRectFilled(grab_rect.Min, grab_rect.Max, grab_col, style.ScrollbarRounding); } -// Moving window to front of display (which happens to be back of our sorted list) +void ImGui::BringWindowToFront(ImGuiWindow* window) +{ + ImGuiContext& g = *GImGui; + if (g.Windows.back() == window) + return; + for (int i = 0; i < g.Windows.Size; i++) + if (g.Windows[i] == window) + { + g.Windows.erase(g.Windows.begin() + i); + g.Windows.push_back(window); + break; + } +} + +void ImGui::BringWindowToBack(ImGuiWindow* window) +{ + ImGuiContext& g = *GImGui; + if (g.Windows[0] == window) + return; + for (int i = 0; i < g.Windows.Size; i++) + if (g.Windows[i] == window) + { + memmove(&g.Windows[1], &g.Windows[0], (size_t)i * sizeof(ImGuiWindow*)); + g.Windows[0] = window; + break; + } +} + +// Moving window to front of display and set focus (which happens to be back of our sorted list) void ImGui::FocusWindow(ImGuiWindow* window) { ImGuiContext& g = *GImGui; @@ -4805,7 +4833,7 @@ void ImGui::FocusWindow(ImGuiWindow* window) if (!window) return; - // And move its root window to the top of the pile + // Move the root window to the top of the pile if (window->RootWindow) window = window->RootWindow; @@ -4815,15 +4843,8 @@ void ImGui::FocusWindow(ImGuiWindow* window) ClearActiveID(); // Bring to front - if ((window->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus) || g.Windows.back() == window) - return; - for (int i = 0; i < g.Windows.Size; i++) - if (g.Windows[i] == window) - { - g.Windows.erase(g.Windows.begin() + i); - break; - } - g.Windows.push_back(window); + if (!(window->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus)) + BringWindowToFront(window); } void ImGui::FocusPreviousWindow() diff --git a/imgui_internal.h b/imgui_internal.h index 85eced9d..be8d84d8 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -779,6 +779,8 @@ namespace ImGui IMGUI_API ImGuiWindow* GetParentWindow(); IMGUI_API ImGuiWindow* FindWindowByName(const char* name); IMGUI_API void FocusWindow(ImGuiWindow* window); + IMGUI_API void BringWindowToFront(ImGuiWindow* window); + IMGUI_API void BringWindowToBack(ImGuiWindow* window); IMGUI_API void Initialize(); IMGUI_API void EndFrame(); // Ends the ImGui frame. Automatically called by Render()! you most likely don't need to ever call that yourself directly. If you don't need to render you can call EndFrame() but you'll have wasted CPU already. If you don't need to render, don't create any windows instead!