From a4629b0b36f8ef1ac588a74b9eca5fb46701e23c Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 9 Mar 2018 15:37:16 +0100 Subject: [PATCH] Viewport, DPI: Select viewport before locking style sizes and before handling double-click-on-title-bar to collapse. (#1542, #1676) --- imgui.cpp | 29 +++++++++++++++-------------- imgui_internal.h | 2 +- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index d7048fcd..3dac7cea 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6291,7 +6291,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) if (g.NextWindowData.CollapsedCond) SetWindowCollapsed(window, g.NextWindowData.CollapsedVal, g.NextWindowData.CollapsedCond); if (g.NextWindowData.FocusCond) - SetWindowFocus(); + FocusWindow(window); if (window->Appearing) SetWindowConditionAllowFlags(window, ImGuiCond_Appearing, false); @@ -6317,6 +6317,20 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->LastFrameActive = current_frame; window->IDStack.resize(1); + // VIEWPORT + // We need to do this before using any style/font sizes, as viewport with a different DPI will affect those sizes. + + UpdateWindowViewport(window, window_pos_set_by_api); + SetCurrentViewport(window->Viewport); + window->Viewport->LastFrameActive = g.FrameCount; + flags = window->Flags; + + if (p_open != NULL && window->Viewport->PlatformRequestClose && !(window->Viewport->Flags & ImGuiViewportFlags_MainViewport)) + { + window->Viewport->PlatformRequestClose = false; + *p_open = false; + } + // Lock window rounding, border size and padding for the frame (so that altering them doesn't cause inconsistencies) window->WindowRounding = (flags & ImGuiWindowFlags_ChildWindow) ? style.ChildRounding : ((flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiWindowFlags_Modal)) ? style.PopupRounding : style.WindowRounding; window->WindowBorderSize = (flags & ImGuiWindowFlags_ChildWindow) ? style.ChildBorderSize : ((flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiWindowFlags_Modal)) ? style.PopupBorderSize : style.WindowBorderSize; @@ -6342,19 +6356,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) } window->CollapseToggleWanted = false; - // VIEWPORT - - UpdateWindowViewport(window, window_pos_set_by_api); - SetCurrentViewport(window->Viewport); - window->Viewport->LastFrameActive = g.FrameCount; - flags = window->Flags; - - if (p_open != NULL && window->Viewport->PlatformRequestClose && !(window->Viewport->Flags & ImGuiViewportFlags_MainViewport)) - { - window->Viewport->PlatformRequestClose = false; - *p_open = false; - } - // SIZE // Update contents size from last frame for auto-fitting (unless explicitly specified) diff --git a/imgui_internal.h b/imgui_internal.h index 06bdbbc8..4aa9a3b9 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1076,7 +1076,7 @@ namespace ImGui inline ImGuiWindow* GetCurrentWindowRead() { ImGuiContext& g = *GImGui; return g.CurrentWindow; } inline ImGuiWindow* GetCurrentWindow() { ImGuiContext& g = *GImGui; g.CurrentWindow->WriteAccessed = true; return g.CurrentWindow; } IMGUI_API ImGuiWindow* FindWindowByName(const char* name); - IMGUI_API void FocusWindow(ImGuiWindow* window); + IMGUI_API void FocusWindow(ImGuiWindow* window); // FIXME: Rename to SetWindowFocus() IMGUI_API void BringWindowToFront(ImGuiWindow* window); IMGUI_API void BringWindowToBack(ImGuiWindow* window); IMGUI_API bool IsWindowChildOf(ImGuiWindow* window, ImGuiWindow* potential_parent);