From e1143377c2621184551d1dcac136e7e4a76e409b Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 30 Jan 2019 21:21:59 +0100 Subject: [PATCH] Viewport: Added ImGuiViewportFlags_NoFocusOnClick + support in imgui_impl_win32. Made windows with no decoration always set the _NoFocus flags. (#1542, #2117) Fix e.g. clicking on protruding combo box stealing highlight from parent window with decoration. --- examples/example_win32_directx11/main.cpp | 4 ++++ examples/imgui_impl_win32.cpp | 4 ++++ imgui.cpp | 2 ++ imgui.h | 7 ++++--- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/example_win32_directx11/main.cpp b/examples/example_win32_directx11/main.cpp index d0a8ae101..a8156cac8 100644 --- a/examples/example_win32_directx11/main.cpp +++ b/examples/example_win32_directx11/main.cpp @@ -139,6 +139,10 @@ int main(int, char**) //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge; io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleFonts; // FIXME-DPI: THIS CURRENTLY DOESN'T WORK AS EXPECTED. DON'T USE IN USER APP! io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleViewports; // FIXME-DPI + //io.ConfigViewportsNoAutoMerge = true; + //io.ConfigViewportsNoTaskBarIcon = false; + //io.ConfigDockingTabBarOnSingleWindows = true; + //io.ConfigDockingTransparentPayload = true; // Setup Dear ImGui style ImGui::StyleColorsDark(); diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index dc55c8e29..7b60dd1b5 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -737,6 +737,10 @@ static LRESULT CALLBACK ImGui_ImplWin32_WndProcHandler_PlatformWindow(HWND hWnd, case WM_SIZE: viewport->PlatformRequestResize = true; break; + case WM_MOUSEACTIVATE: + if (viewport->Flags & ImGuiViewportFlags_NoFocusOnClick) + return MA_NOACTIVATE; + break; case WM_NCHITTEST: // Let mouse pass-through the window. This will allow the back-end to set io.MouseHoveredViewport properly (which is OPTIONAL). // The ImGuiViewportFlags_NoInputs flag is set while dragging a viewport, as want to detect the window behind the one we are dragging. diff --git a/imgui.cpp b/imgui.cpp index 83470b3ee..9d84c7eef 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5520,6 +5520,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) viewport_flags |= ImGuiViewportFlags_NoTaskBarIcon; if (g.IO.ConfigViewportsNoDecoration || (flags & (ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup)) != 0) viewport_flags |= ImGuiViewportFlags_NoDecoration; + if ((viewport_flags & ImGuiViewportFlags_NoDecoration) && (viewport_flags & ImGuiViewportFlags_NoTaskBarIcon)) + viewport_flags |= ImGuiViewportFlags_NoFocusOnAppearing | ImGuiViewportFlags_NoFocusOnClick; // We can overwrite viewport flags using ImGuiWindowClass (advanced users) // We don't default to the main viewport because. diff --git a/imgui.h b/imgui.h index 00f8cd5b9..212c16b34 100644 --- a/imgui.h +++ b/imgui.h @@ -2298,9 +2298,10 @@ enum ImGuiViewportFlags_ ImGuiViewportFlags_NoDecoration = 1 << 0, // Platform Window: Disable platform decorations: title bar, borders, etc. (generally set all windows, but if ImGuiConfigFlags_ViewportsDecoration is set we only set this on popups/tooltips) ImGuiViewportFlags_NoTaskBarIcon = 1 << 1, // Platform Window: Disable platform task bar icon (generally set on popups/tooltips, or all windows if ImGuiConfigFlags_ViewportsNoTaskBarIcon is set) ImGuiViewportFlags_NoFocusOnAppearing = 1 << 2, // Platform Window: Don't take focus when created. - ImGuiViewportFlags_NoInputs = 1 << 3, // Platform Window: Make mouse pass through so we can drag this window while peaking behind it. - ImGuiViewportFlags_NoRendererClear = 1 << 4, // Platform Window: Renderer doesn't need to clear the framebuffer ahead (because we will fill it entirely). - ImGuiViewportFlags_TopMost = 1 << 5 // Platform Window: Display on top (for tooltips only) + ImGuiViewportFlags_NoFocusOnClick = 1 << 3, // Platform Window: Don't take focus when clicked on. + ImGuiViewportFlags_NoInputs = 1 << 4, // Platform Window: Make mouse pass through so we can drag this window while peaking behind it. + ImGuiViewportFlags_NoRendererClear = 1 << 5, // Platform Window: Renderer doesn't need to clear the framebuffer ahead (because we will fill it entirely). + ImGuiViewportFlags_TopMost = 1 << 6 // Platform Window: Display on top (for tooltips only) }; // The viewports created and managed by imgui. The role of the platform back-end is to create the platform/OS windows corresponding to each viewport.