Viewport: Fix lagging overlay clipping rectangle on viewport owning window (affecting sync of multi-layered docking overlays). This was extremely tricky to find and fix (*). (#1541)

(*) Merely assigning viewport->Pos = pos in UpdateMovingWindow() broke a series of thing because the code that assign viewports and viewport flags relied on moving window leaving its own viewport the first time to set the NoInputs flag.
This commit is contained in:
omar 2018-06-15 19:38:17 +02:00
parent c71522adc5
commit 7e6700d261

View File

@ -3612,6 +3612,8 @@ static void ImGui::UpdateMovingWindow()
{ {
MarkIniSettingsDirty(moving_window); MarkIniSettingsDirty(moving_window);
SetWindowPos(moving_window, pos, ImGuiCond_Always); SetWindowPos(moving_window, pos, ImGuiCond_Always);
if (moving_window->ViewportOwned) // Synchronize viewport immediately because some overlays may relies on clipping rectangle before we Begin() into the window.
moving_window->Viewport->Pos = pos;
} }
FocusWindow(g.MovingWindow); FocusWindow(g.MovingWindow);
} }
@ -6612,8 +6614,12 @@ static void ImGui::UpdateSelectWindowViewport(ImGuiWindow* window)
} }
else if (g.MovingWindow && g.MovingWindow->RootWindow == window && IsMousePosValid()) else if (g.MovingWindow && g.MovingWindow->RootWindow == window && IsMousePosValid())
{ {
// Transition to a standalone viewport // Transition to our own viewport when leaving our host boundaries + set the NoInputs flag (which will be cleared in UpdateMovingWindow when releasing the mouse)
if (!window->Viewport->GetRect().Contains(window->Rect())) // If we are already in our own viewport, if need to set the NoInputs flag.
bool own_viewport = window->Viewport->Window == window; // We test window->Viewport->Window because window->ViewportOwned is not valid during this function.
bool leave_host_viewport = !own_viewport && !window->Viewport->GetRect().Contains(window->Rect());
bool move_from_own_viewport = own_viewport && !(window->Viewport->Flags & ImGuiViewportFlags_NoInputs);
if (leave_host_viewport || move_from_own_viewport)
window->Viewport = AddUpdateViewport(window, window->ID, window->Pos, window->Size, ImGuiViewportFlags_NoDecoration | ImGuiViewportFlags_NoFocusOnAppearing | ImGuiViewportFlags_NoInputs); window->Viewport = AddUpdateViewport(window, window->ID, window->Pos, window->Size, ImGuiViewportFlags_NoDecoration | ImGuiViewportFlags_NoFocusOnAppearing | ImGuiViewportFlags_NoInputs);
} }
else if (GetWindowAlwaysWantOwnViewport(window)) else if (GetWindowAlwaysWantOwnViewport(window))