Skip to content

Commit

Permalink
Docking: prevent docking any window created above a popup/modal. (#4317)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocornut committed Dec 9, 2021
1 parent f605351 commit 747f7fd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ Docking+Viewports Branch:
- Docking, Style: Docked windows honor display their border properly. (#2522)
- Docking: Fixed incorrectly rounded tab bars for dock node that are not at the top of their dock tree.
- Docking: Fixed single-frame node pos/size inconsistencies when window stop or start being submitted.
- Docking: Prevent docking any window created above a popup/modal. (#4317)
- Viewports: Made it possible to explicitly assign ImGuiWindowClass::ParentViewportId to 0 in order
to ensure a window is not parented. Previously this would use the global default (which might be 0,
but not always as it would depend on io.ConfigViewportsNoDefaultParent). (#3152, #2871)
Expand Down
13 changes: 12 additions & 1 deletion imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14897,12 +14897,23 @@ static bool DockNodeIsDropAllowedOne(ImGuiWindow* payload, ImGuiWindow* host_win
return false;
}

// Prevent docking any window created above a popup
// Technically we should support it (e.g. in the case of a long-lived modal window that had fancy docking features),
// by e.g. adding a 'if (!ImGui::IsWindowWithinBeginStackOf(host_window, popup_window))' test.
// But it would requires more work on our end because the dock host windows is technically created in NewFrame()
// and our ->ParentXXX and ->RootXXX pointers inside windows are currently mislading or lacking.
ImGuiContext& g = *GImGui;
for (int i = g.OpenPopupStack.Size - 1; i >= 0; i--)
if (ImGuiWindow* popup_window = g.OpenPopupStack[i].Window)
if (ImGui::IsWindowWithinBeginStackOf(payload, popup_window)) // Payload is created from within a popup begin stack.
return false;

return true;
}

static bool ImGui::DockNodeIsDropAllowed(ImGuiWindow* host_window, ImGuiWindow* root_payload)
{
if (root_payload->DockNodeAsHost && root_payload->DockNodeAsHost->IsSplitNode())
if (root_payload->DockNodeAsHost && root_payload->DockNodeAsHost->IsSplitNode()) // FIXME-DOCK: Missing filtering
return true;

const int payload_count = root_payload->DockNodeAsHost ? root_payload->DockNodeAsHost->Windows.Size : 1;
Expand Down

0 comments on commit 747f7fd

Please sign in to comment.