Skip to content

Commit

Permalink
Viewports: fixed unnecessary creation of temporary viewports when mul…
Browse files Browse the repository at this point in the history
…tiple docked windows got reassigned to a new node (created mid-frame) which already has a HostWindow
  • Loading branch information
ocornut committed Sep 9, 2021
1 parent 6b1e094 commit 9a49c1d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 4 additions & 2 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ Docking+Viewports Branch:
- IsWindowHovered: Fixed using ImGuiHoveredFlags_ChildWindows (without _RootWindow) from leaking the
docking hierarchy. Added ImGuiHoveredFlags_DockHierarchy flag to consider docking hierarchy in the test.
- Docking: fixed settings load issue when mouse wheeling. (#4310)
- Drag and Drop: Fixed using BeginDragDropSource() or BeginDragDropTarget() inside a Begin() that
returned false because the window is docked. (#4515)
- Docking + Drag and Drop: Fixed using BeginDragDropSource() or BeginDragDropTarget() inside a Begin()
that returned false because the window is docked. (#4515)
- Viewports: Viewports: fixed unnecessary creation of temporary viewports when multiple docked windows
got reassigned to a new node (created mid-frame) which already has a HostWindow.


-----------------------------------------------------------------------
Expand Down
10 changes: 9 additions & 1 deletion imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12008,8 +12008,15 @@ static void ImGui::WindowSelectViewport(ImGuiWindow* window)
else if ((flags & ImGuiWindowFlags_ChildWindow) || (flags & ImGuiWindowFlags_ChildMenu))
{
// Always inherit viewport from parent window
if (window->DockNode && window->DockNode->HostWindow)
IM_ASSERT(window->DockNode->HostWindow->Viewport == window->ParentWindow->Viewport);
window->Viewport = window->ParentWindow->Viewport;
}
else if (window->DockNode && window->DockNode->HostWindow)
{
// This covers the "always inherit viewport from parent window" case for when a window reattach to a node that was just created mid-frame
window->Viewport = window->DockNode->HostWindow->Viewport;
}
else if (flags & ImGuiWindowFlags_Tooltip)
{
window->Viewport = g.MouseViewport;
Expand Down Expand Up @@ -12052,7 +12059,7 @@ static void ImGui::WindowSelectViewport(ImGuiWindow* window)
else
window->ViewportAllowPlatformMonitorExtend = window->Viewport->PlatformMonitor;
}
else if (window->Viewport && window != window->Viewport->Window && window->Viewport->Window && !(flags & ImGuiWindowFlags_ChildWindow))
else if (window->Viewport && window != window->Viewport->Window && window->Viewport->Window && !(flags & ImGuiWindowFlags_ChildWindow) && window->DockNode == NULL)
{
// When called from Begin() we don't have access to a proper version of the Hidden flag yet, so we replicate this code.
const bool will_be_visible = (window->DockIsActive && !window->DockTabIsVisible) ? false : true;
Expand Down Expand Up @@ -13445,6 +13452,7 @@ static void ImGui::DockNodeRemoveWindow(ImGuiDockNode* node, ImGuiWindow* window
if (node->HostWindow->ViewportOwned && node->IsRootNode())
{
// Transfer viewport back to the remaining loose window
IMGUI_DEBUG_LOG_VIEWPORT("Node %08X transfer Viewport %08X=>%08X for Window '%s'\n", node->ID, node->HostWindow->Viewport->ID, remaining_window->ID, remaining_window->Name);
IM_ASSERT(node->HostWindow->Viewport->Window == node->HostWindow);
node->HostWindow->Viewport->Window = remaining_window;
node->HostWindow->Viewport->ID = remaining_window->ID;
Expand Down

0 comments on commit 9a49c1d

Please sign in to comment.