Viewport: Made it possible for the moving window to detach and recreate its own Viewport (used by Docking)

This commit is contained in:
omar 2018-06-27 17:27:27 +02:00
parent 140ece0aeb
commit 9dea27b273

View File

@ -5536,6 +5536,11 @@ static void FindHoveredWindow()
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
// Special handling for the window being moved: Ignore the mouse viewport check (because it may reset/lose its viewport during the undocking frame)
ImGuiViewportP* moving_window_viewport = g.MovingWindow ? g.MovingWindow->Viewport : NULL;
if (g.MovingWindow)
g.MovingWindow->Viewport = g.MouseRefViewport;
ImGuiWindow* hovered_window = NULL; ImGuiWindow* hovered_window = NULL;
ImGuiWindow* hovered_window_ignoring_moving_window = NULL; ImGuiWindow* hovered_window_ignoring_moving_window = NULL;
if (g.MovingWindow && !(g.MovingWindow->Flags & ImGuiWindowFlags_NoInputs)) if (g.MovingWindow && !(g.MovingWindow->Flags & ImGuiWindowFlags_NoInputs))
@ -5568,6 +5573,9 @@ static void FindHoveredWindow()
g.HoveredWindow = hovered_window; g.HoveredWindow = hovered_window;
g.HoveredRootWindow = g.HoveredWindow ? g.HoveredWindow->RootWindow : NULL; g.HoveredRootWindow = g.HoveredWindow ? g.HoveredWindow->RootWindow : NULL;
g.HoveredWindowUnderMovingWindow = hovered_window_ignoring_moving_window; g.HoveredWindowUnderMovingWindow = hovered_window_ignoring_moving_window;
if (g.MovingWindow)
g.MovingWindow->Viewport = moving_window_viewport;
} }
// Test if mouse cursor is hovering given rectangle // Test if mouse cursor is hovering given rectangle
@ -6764,6 +6772,8 @@ static void ImGui::UpdateSelectWindowViewport(ImGuiWindow* window)
window->ViewportId = 0; window->ViewportId = 0;
} }
if (!g.NextWindowData.ViewportCond)
{
// By default inherit from parent window // By default inherit from parent window
if (window->Viewport == NULL && window->ParentWindow) if (window->Viewport == NULL && window->ParentWindow)
window->Viewport = window->ParentWindow->Viewport; window->Viewport = window->ParentWindow->Viewport;
@ -6775,6 +6785,7 @@ static void ImGui::UpdateSelectWindowViewport(ImGuiWindow* window)
if (window->Viewport == NULL && window->ViewportPos.x != FLT_MAX && window->ViewportPos.y != FLT_MAX) if (window->Viewport == NULL && window->ViewportPos.x != FLT_MAX && window->ViewportPos.y != FLT_MAX)
window->Viewport = AddUpdateViewport(window, window->ID, window->ViewportPos, window->Size, ImGuiViewportFlags_NoDecoration); window->Viewport = AddUpdateViewport(window, window->ID, window->ViewportPos, window->Size, ImGuiViewportFlags_NoDecoration);
} }
}
if (g.NextWindowData.ViewportCond) if (g.NextWindowData.ViewportCond)
{ {
@ -6795,10 +6806,13 @@ static void ImGui::UpdateSelectWindowViewport(ImGuiWindow* window)
{ {
// Transition to our own viewport when leaving our host boundaries + set the NoInputs flag (which will be cleared in UpdateMovingWindow when releasing the mouse) // 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 we are already in our own viewport, if need to set the NoInputs flag. // 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. // If we have no viewport (which happens when detaching a docked node) immediately create one.
bool leave_host_viewport = !own_viewport && !window->Viewport->GetRect().Contains(window->Rect()); // We test for 'window->Viewport->Window == window' instead of 'window->ViewportOwned' because ViewportOwned is not valid during this function.
bool move_from_own_viewport = own_viewport && !(window->Viewport->Flags & ImGuiViewportFlags_NoInputs); bool has_viewport = (window->Viewport != NULL);
if (leave_host_viewport || move_from_own_viewport) bool own_viewport = has_viewport && (window->Viewport->Window == window);
bool leave_host_viewport = has_viewport && !own_viewport && !window->Viewport->GetRect().Contains(window->Rect());
bool move_from_own_viewport = has_viewport && own_viewport && !(window->Viewport->Flags & ImGuiViewportFlags_NoInputs);
if (!has_viewport || 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))