mirror of
https://github.com/ocornut/imgui.git
synced 2024-12-13 21:19:02 +08:00
Docking: Preserve existing docked nodes when setting the ImGuiDockNodeFlags_NoDockingInCentralNode flag. (#2423, #2109)
This commit is contained in:
parent
7ba774a440
commit
c7619d4a6a
11
imgui.cpp
11
imgui.cpp
@ -12873,7 +12873,7 @@ void ImGui::SetWindowDock(ImGuiWindow* window, ImGuiID dock_id, ImGuiCond cond)
|
||||
|
||||
// Create an explicit dockspace node within an existing window. Also expose dock node flags and creates a CentralNode by default.
|
||||
// The Central Node is always displayed even when empty and shrink/extend according to the requested size of its neighbors.
|
||||
void ImGui::DockSpace(ImGuiID id, const ImVec2& size_arg, ImGuiDockNodeFlags dockspace_flags, const ImGuiWindowClass* window_class)
|
||||
void ImGui::DockSpace(ImGuiID id, const ImVec2& size_arg, ImGuiDockNodeFlags flags, const ImGuiWindowClass* window_class)
|
||||
{
|
||||
ImGuiContext* ctx = GImGui;
|
||||
ImGuiContext& g = *ctx;
|
||||
@ -12881,18 +12881,19 @@ void ImGui::DockSpace(ImGuiID id, const ImVec2& size_arg, ImGuiDockNodeFlags doc
|
||||
if (!(g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable))
|
||||
return;
|
||||
|
||||
IM_ASSERT((flags & ImGuiDockNodeFlags_Dockspace) == 0);
|
||||
ImGuiDockNode* node = DockContextFindNodeByID(ctx, id);
|
||||
if (!node)
|
||||
{
|
||||
node = DockContextAddNode(ctx, id);
|
||||
node->IsCentralNode = true;
|
||||
}
|
||||
node->Flags = dockspace_flags;
|
||||
node->Flags = flags;
|
||||
node->WindowClass = window_class ? *window_class : ImGuiWindowClass();
|
||||
|
||||
// When a Dockspace transitioned form implicit to explicit this may be called a second time
|
||||
// It is possible that the node has already been claimed by a docked window which appeared before the DockSpace() node, so we overwrite IsDockSpace again.
|
||||
if (node->LastFrameActive == g.FrameCount && !(dockspace_flags & ImGuiDockNodeFlags_KeepAliveOnly))
|
||||
if (node->LastFrameActive == g.FrameCount && !(flags & ImGuiDockNodeFlags_KeepAliveOnly))
|
||||
{
|
||||
IM_ASSERT(node->IsDockSpace() == false && "Cannot call DockSpace() twice a frame with the same ID");
|
||||
node->Flags |= ImGuiDockNodeFlags_Dockspace;
|
||||
@ -12901,7 +12902,7 @@ void ImGui::DockSpace(ImGuiID id, const ImVec2& size_arg, ImGuiDockNodeFlags doc
|
||||
node->Flags |= ImGuiDockNodeFlags_Dockspace;
|
||||
|
||||
// Keep alive mode, this is allow windows docked into this node so stay docked even if they are not visible
|
||||
if (dockspace_flags & ImGuiDockNodeFlags_KeepAliveOnly)
|
||||
if (flags & ImGuiDockNodeFlags_KeepAliveOnly)
|
||||
{
|
||||
node->LastFrameAlive = g.FrameCount;
|
||||
return;
|
||||
@ -13421,12 +13422,14 @@ void ImGui::BeginDocked(ImGuiWindow* window, bool* p_open)
|
||||
g.NextWindowData.PosUndock = false;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// Undock if the ImGuiDockNodeFlags_NoDockingInCentralNode got set
|
||||
if (node->IsCentralNode && (node->Flags & ImGuiDockNodeFlags_NoDockingInCentralNode))
|
||||
{
|
||||
DockContextProcessUndockWindow(ctx, window);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Undock if our dockspace node disappeared
|
||||
// Note how we are testing for LastFrameAlive and NOT LastFrameActive. A DockSpace node can be maintained alive while being inactive with ImGuiDockNodeFlags_KeepAliveOnly.
|
||||
|
6
imgui.h
6
imgui.h
@ -594,7 +594,7 @@ namespace ImGui
|
||||
// To dock windows: hold SHIFT anywhere while moving windows (if io.ConfigDockingWithShift == true) or drag windows from their title bar (if io.ConfigDockingWithShift = false)
|
||||
// Use DockSpace() to create an explicit dock node _within_ an existing window. See Docking demo for details.
|
||||
IMGUI_API void DockSpace(ImGuiID id, const ImVec2& size = ImVec2(0, 0), ImGuiDockNodeFlags flags = 0, const ImGuiWindowClass* window_class = NULL);
|
||||
IMGUI_API ImGuiID DockSpaceOverViewport(ImGuiViewport* viewport = NULL, ImGuiDockNodeFlags dockspace_flags = 0, const ImGuiWindowClass* window_class = NULL);
|
||||
IMGUI_API ImGuiID DockSpaceOverViewport(ImGuiViewport* viewport = NULL, ImGuiDockNodeFlags flags = 0, const ImGuiWindowClass* window_class = NULL);
|
||||
IMGUI_API void SetNextWindowDockID(ImGuiID dock_id, ImGuiCond cond = 0); // set next window dock id (FIXME-DOCK)
|
||||
IMGUI_API void SetNextWindowClass(const ImGuiWindowClass* window_class); // set next window class (rare/advanced uses: provide hints to the platform back-end via altered viewport flags and parent/child info)
|
||||
IMGUI_API ImGuiID GetWindowDockID();
|
||||
@ -882,9 +882,9 @@ enum ImGuiDockNodeFlags_
|
||||
{
|
||||
ImGuiDockNodeFlags_None = 0,
|
||||
ImGuiDockNodeFlags_KeepAliveOnly = 1 << 0, // Don't display the dockspace node but keep it alive. Windows docked into this dockspace node won't be undocked.
|
||||
ImGuiDockNodeFlags_NoSplit = 1 << 1, // Disable splitting the node into smaller nodes. Useful e.g. when embedding dockspaces into a main root one (the root one may have splitting disabled to reduce confusion)
|
||||
ImGuiDockNodeFlags_NoSplit = 1 << 1, // Disable splitting the node into smaller nodes. Useful e.g. when embedding dockspaces into a main root one (the root one may have splitting disabled to reduce confusion). Note: when turned off, existing splits will be preserved.
|
||||
//ImGuiDockNodeFlags_NoCentralNode = 1 << 2, // Disable Central Node (the node which can stay empty)
|
||||
ImGuiDockNodeFlags_NoDockingInCentralNode = 1 << 3, // Disable docking inside the Central Node, which will be always kept empty.
|
||||
ImGuiDockNodeFlags_NoDockingInCentralNode = 1 << 3, // Disable docking inside the Central Node, which will be always kept empty. Note: when turned off, existing docked nodes will be preserved.
|
||||
//ImGuiDockNodeFlags_NoLayoutChanges = 1 << 4, // Disable adding/removing nodes interactively. Useful with programatically setup dockspaces.
|
||||
ImGuiDockNodeFlags_NoResize = 1 << 5, // Disable resizing child nodes using the splitter/separators. Useful with programatically setup dockspaces.
|
||||
ImGuiDockNodeFlags_PassthruDockspace = 1 << 6, // Enable passthru dockspace: 1) DockSpace() will render a ImGuiCol_WindowBg background covering everything excepted the Central Node when empty. Meaning the host window should probably use SetNextWindowBgAlpha(0.0f) prior to Begin() when using this. 2) When Central Node is empty: let inputs pass-through + won't display a DockingEmptyBg background.
|
||||
|
Loading…
Reference in New Issue
Block a user