Skip to content

Commit

Permalink
Docking: undocking nodes/windows covering most of the monitor max the…
Browse files Browse the repository at this point in the history
…ir size down to 90% to ease further manipulations.

Kind of a welcome hack.
  • Loading branch information
ocornut committed Mar 16, 2021
1 parent 2231e1a commit b202fa9
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12815,6 +12815,29 @@ void ImGui::DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req)
MarkIniSettingsDirty();
}

// Problem:
// Undocking a large (~full screen) window would leave it so large that the bottom right sizing corner would more
// than likely be off the screen and the window would be hard to resize to fit on screen. This can be particularly problematic
// with 'ConfigWindowsMoveFromTitleBarOnly=true' and/or with 'ConfigWindowsResizeFromEdges=false' as well (the later can be
// due to missing ImGuiBackendFlags_HasMouseCursors backend flag).
// Solution:
// When undocking a window we currently force its maximum size to 90% of the host viewport or monitor.
// Reevaluate this when we implement preserving docked/undocked size ("docking_wip/undocked_size" branch).
static ImVec2 FixLargeWindowsWhenUndocking(const ImVec2& size, ImGuiViewport* ref_viewport)
{
if (ref_viewport == NULL)
return size;

ImGuiContext& g = *GImGui;
ImVec2 max_size = ImFloor(ref_viewport->WorkSize * 0.90f);
if (g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable)
{
const ImGuiPlatformMonitor* monitor = ImGui::GetViewportPlatformMonitor(ref_viewport);
max_size = ImFloor(monitor->WorkSize * 0.90f);
}
return ImMin(size, max_size);
}

void ImGui::DockContextProcessUndockWindow(ImGuiContext* ctx, ImGuiWindow* window, bool clear_persistent_docking_ref)
{
IMGUI_DEBUG_LOG_DOCKING("DockContextProcessUndockWindow window '%s', clear_persistent_docking_ref = %d\n", window->Name, clear_persistent_docking_ref);
Expand All @@ -12826,6 +12849,8 @@ void ImGui::DockContextProcessUndockWindow(ImGuiContext* ctx, ImGuiWindow* windo
window->Collapsed = false;
window->DockIsActive = false;
window->DockTabIsVisible = false;
window->Size = window->SizeFull = FixLargeWindowsWhenUndocking(window->SizeFull, window->Viewport);

MarkIniSettingsDirty();
}

Expand All @@ -12839,6 +12864,9 @@ void ImGui::DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node)
{
// In the case of a root node or central node, the node will have to stay in place. Create a new node to receive the payload.
ImGuiDockNode* new_node = DockContextAddNode(ctx, 0);
new_node->Pos = node->Pos;
new_node->Size = node->Size;
new_node->SizeRef = node->SizeRef;
DockNodeMoveWindows(new_node, node);
DockSettingsRenameNodeReferences(node->ID, new_node->ID);
for (int n = 0; n < new_node->Windows.Size; n++)
Expand All @@ -12847,15 +12875,16 @@ void ImGui::DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node)
}
else
{
// Otherwise extract our node and merging our sibling back into the parent node.
// Otherwise extract our node and merge our sibling back into the parent node.
IM_ASSERT(node->ParentNode->ChildNodes[0] == node || node->ParentNode->ChildNodes[1] == node);
int index_in_parent = (node->ParentNode->ChildNodes[0] == node) ? 0 : 1;
node->ParentNode->ChildNodes[index_in_parent] = NULL;
DockNodeTreeMerge(ctx, node->ParentNode, node->ParentNode->ChildNodes[index_in_parent ^ 1]);
node->ParentNode->AuthorityForViewport = ImGuiDataAuthority_Window; // The node that stays in place keeps the viewport, so our newly dragged out node will create a new viewport
node->ParentNode = NULL;
}
node->AuthorityForPos = node->AuthorityForSize = ImGuiDataAuthority_Window;
node->AuthorityForPos = node->AuthorityForSize = ImGuiDataAuthority_DockNode;
node->Size = FixLargeWindowsWhenUndocking(node->Size, node->Windows[0]->Viewport);
node->WantMouseMove = true;
MarkIniSettingsDirty();
}
Expand Down

0 comments on commit b202fa9

Please sign in to comment.