Skip to content

Multiple viewports not merged if something has active focus. #4212

@magcius

Description

@magcius

Version/Branch of Dear ImGui:

Dear ImGui 1.80 (18000)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 4, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: IMGUI_DISABLE_DEFAULT_ALLOCATORS
define: _WIN32
define: _WIN64
define: _MSC_VER=1928
define: _MSVC_LANG=201402
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: Propeller
io.BackendRendererName: NULL
io.ConfigFlags: 0x00000441
 NavEnableKeyboard
 DockingEnable
 ViewportsEnable
io.ConfigViewportsNoDecoration
io.ConfigDockingAlwaysTabBar
io.ConfigDockingTransparentPayload
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C02
 HasMouseCursors
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasViewports
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1553.00,825.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 1.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Back-end/Renderer/Compiler/OS

Back-ends: Custom backend on top of SDL2, Win32
Compiler: MSVC
Operating System: Windows 10

My Issue/Question:

I'm looking into issues in a work-in-progress game related to window resizing and platform window generation. I'm still narrowing things down, but I've found a weird behavior I believe is a bug. Viewports are only merged if g.ActiveId == 0:

imgui/imgui.cpp

Lines 11924 to 11928 in db0338a

// Merge into host viewport?
// We cannot test window->ViewportOwned as it set lower in the function.
bool try_to_merge_into_host_viewport = (window->Viewport && window == window->Viewport->Window && g.ActiveId == 0);
if (try_to_merge_into_host_viewport)
UpdateTryMergeWindowIntoHostViewports(window);

I believe this intended to prevent a window from disappearing if it has focus, but since the ActiveId tracks global focus, windows are not merged. This seems wrong to me.

Standalone, minimal, complete and verifiable example:

This can be reproduced from the ImGui demo:

  1. Open the Log example and About Dear ImGui window.
  2. Drag the About Dear ImGui window to the side so that a new platform window is created.
  3. Click in the Filter textbox on the Log example so that it gains focus.
  4. Resize the parent window to be larger so that it now fully encompasses the About Dear ImGui window.
  5. Expect it to be absorbed into the parent viewport, but it is not.
  6. Click elsewhere to make the Filter textbox loses focus, and watch the About Dear ImGui get absorbed into the parent window.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions