mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-19 06:26:35 +00:00
Docking: fix BeginDocked() path that creates node so that SetNextWindowDockID() doesn't immediately discard the node..(#2109)
Amend 515ecbddc2
, not sure at this point if the (auto_dock_node) flag was needed at all.
Comments. Exposed DockContextGenNodeID() in imgui_internal.h
This commit is contained in:
parent
d8f9f6ba2a
commit
27431dcc6b
18
imgui.cpp
18
imgui.cpp
@ -3823,9 +3823,9 @@ void ImGui::NewFrame()
|
|||||||
// Perform simple check: error if Docking or Viewport are enabled _exactly_ on frame 1 (instead of frame 0 or later), which is a common error leading to loss of .ini data.
|
// Perform simple check: error if Docking or Viewport are enabled _exactly_ on frame 1 (instead of frame 0 or later), which is a common error leading to loss of .ini data.
|
||||||
g.ConfigFlagsLastFrame = g.ConfigFlagsCurrFrame;
|
g.ConfigFlagsLastFrame = g.ConfigFlagsCurrFrame;
|
||||||
if (g.FrameCount == 1 && (g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable) && (g.ConfigFlagsLastFrame & ImGuiConfigFlags_DockingEnable) == 0)
|
if (g.FrameCount == 1 && (g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable) && (g.ConfigFlagsLastFrame & ImGuiConfigFlags_DockingEnable) == 0)
|
||||||
IM_ASSERT(0 && "Please DockingEnable before the first call to NewFrame()! Otherwise you will lose your .ini settings!");
|
IM_ASSERT(0 && "Please set DockingEnable before the first call to NewFrame()! Otherwise you will lose your .ini settings!");
|
||||||
if (g.FrameCount == 1 && (g.IO.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) && (g.ConfigFlagsLastFrame & ImGuiConfigFlags_ViewportsEnable) == 0)
|
if (g.FrameCount == 1 && (g.IO.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) && (g.ConfigFlagsLastFrame & ImGuiConfigFlags_ViewportsEnable) == 0)
|
||||||
IM_ASSERT(0 && "Please ViewportEnable before the first call to NewFrame()! Otherwise you will lose your .ini settings!");
|
IM_ASSERT(0 && "Please set ViewportsEnable before the first call to NewFrame()! Otherwise you will lose your .ini settings!");
|
||||||
|
|
||||||
// Perform simple checks: multi-viewport and platform windows support
|
// Perform simple checks: multi-viewport and platform windows support
|
||||||
if (g.IO.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
if (g.IO.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
@ -11190,7 +11190,6 @@ namespace ImGui
|
|||||||
{
|
{
|
||||||
// ImGuiDockContext
|
// ImGuiDockContext
|
||||||
static ImGuiDockNode* DockContextAddNode(ImGuiContext* ctx, ImGuiID id);
|
static ImGuiDockNode* DockContextAddNode(ImGuiContext* ctx, ImGuiID id);
|
||||||
static ImGuiID DockContextGenNodeID(ImGuiContext* ctx);
|
|
||||||
static void DockContextRemoveNode(ImGuiContext* ctx, ImGuiDockNode* node, bool merge_sibling_into_parent_node);
|
static void DockContextRemoveNode(ImGuiContext* ctx, ImGuiDockNode* node, bool merge_sibling_into_parent_node);
|
||||||
static void DockContextQueueNotifyRemovedNode(ImGuiContext* ctx, ImGuiDockNode* node);
|
static void DockContextQueueNotifyRemovedNode(ImGuiContext* ctx, ImGuiDockNode* node);
|
||||||
static void DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req);
|
static void DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req);
|
||||||
@ -11396,7 +11395,7 @@ static ImGuiDockNode* ImGui::DockContextFindNodeByID(ImGuiContext* ctx, ImGuiID
|
|||||||
return (ImGuiDockNode*)ctx->DockContext->Nodes.GetVoidPtr(id);
|
return (ImGuiDockNode*)ctx->DockContext->Nodes.GetVoidPtr(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ImGuiID ImGui::DockContextGenNodeID(ImGuiContext* ctx)
|
ImGuiID ImGui::DockContextGenNodeID(ImGuiContext* ctx)
|
||||||
{
|
{
|
||||||
// Generate an ID for new node (the exact ID value doesn't matter as long as it is not already used)
|
// Generate an ID for new node (the exact ID value doesn't matter as long as it is not already used)
|
||||||
// FIXME-OPT FIXME-DOCKING: This is suboptimal, even if the node count is small enough not to be a worry. We should poke in ctx->Nodes to find a suitable ID faster.
|
// FIXME-OPT FIXME-DOCKING: This is suboptimal, even if the node count is small enough not to be a worry. We should poke in ctx->Nodes to find a suitable ID faster.
|
||||||
@ -11413,6 +11412,8 @@ static ImGuiDockNode* ImGui::DockContextAddNode(ImGuiContext* ctx, ImGuiID id)
|
|||||||
id = DockContextGenNodeID(ctx);
|
id = DockContextGenNodeID(ctx);
|
||||||
else
|
else
|
||||||
IM_ASSERT(DockContextFindNodeByID(ctx, id) == NULL);
|
IM_ASSERT(DockContextFindNodeByID(ctx, id) == NULL);
|
||||||
|
|
||||||
|
// We don't set node->LastFrameAlive on construction. Nodes are always created at all time to reflect .ini settings!
|
||||||
IMGUI_DEBUG_LOG_DOCKING("DockContextAddNode 0x%08X\n", id);
|
IMGUI_DEBUG_LOG_DOCKING("DockContextAddNode 0x%08X\n", id);
|
||||||
ImGuiDockNode* node = IM_NEW(ImGuiDockNode)(id);
|
ImGuiDockNode* node = IM_NEW(ImGuiDockNode)(id);
|
||||||
ctx->DockContext->Nodes.SetVoidPtr(node->ID, node);
|
ctx->DockContext->Nodes.SetVoidPtr(node->ID, node);
|
||||||
@ -11917,8 +11918,8 @@ static void ImGui::DockNodeAddWindow(ImGuiDockNode* node, ImGuiWindow* window, b
|
|||||||
window->DockIsActive = (node->Windows.Size > 1);
|
window->DockIsActive = (node->Windows.Size > 1);
|
||||||
window->DockTabWantClose = false;
|
window->DockTabWantClose = false;
|
||||||
|
|
||||||
// If 2+ windows appeared on the same frame, creating a new DockNode+TabBar from the second window,
|
// If more than 2 windows appeared on the same frame, we'll create a new hosting DockNode from the point of the second window submission.
|
||||||
// then we need to hide the first one after the fact otherwise it would be visible as a standalone window for one frame.
|
// Then we need to hide the first window (after its been output) otherwise it would be visible as a standalone window for one frame.
|
||||||
if (node->HostWindow == NULL && node->Windows.Size == 2 && node->Windows[0]->WasActive == false)
|
if (node->HostWindow == NULL && node->Windows.Size == 2 && node->Windows[0]->WasActive == false)
|
||||||
{
|
{
|
||||||
node->Windows[0]->Hidden = true;
|
node->Windows[0]->Hidden = true;
|
||||||
@ -12464,6 +12465,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node)
|
|||||||
if (node->IsRootNode() && (g.MovingWindow == NULL || g.MovingWindow->RootWindow != host_window))
|
if (node->IsRootNode() && (g.MovingWindow == NULL || g.MovingWindow->RootWindow != host_window))
|
||||||
BeginAsDockableDragDropTarget(host_window);
|
BeginAsDockableDragDropTarget(host_window);
|
||||||
|
|
||||||
|
// We update this after DockNodeUpdateTabBar()
|
||||||
node->LastFrameActive = g.FrameCount;
|
node->LastFrameActive = g.FrameCount;
|
||||||
|
|
||||||
// Recurse into children
|
// Recurse into children
|
||||||
@ -14087,8 +14089,7 @@ void ImGui::BeginDocked(ImGuiWindow* window, bool* p_open)
|
|||||||
{
|
{
|
||||||
node = DockContextAddNode(ctx, window->DockId);
|
node = DockContextAddNode(ctx, window->DockId);
|
||||||
node->AuthorityForPos = node->AuthorityForSize = node->AuthorityForViewport = ImGuiDataAuthority_Window;
|
node->AuthorityForPos = node->AuthorityForSize = node->AuthorityForViewport = ImGuiDataAuthority_Window;
|
||||||
if (auto_dock_node)
|
node->LastFrameAlive = g.FrameCount;
|
||||||
node->LastFrameAlive = g.FrameCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the node just turned visible, it doesn't have a Size assigned by DockNodeTreeUpdatePosSize() yet,
|
// If the node just turned visible, it doesn't have a Size assigned by DockNodeTreeUpdatePosSize() yet,
|
||||||
@ -14913,6 +14914,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
|||||||
IM_ASSERT(node->ChildNodes[1] == NULL || node->ChildNodes[1]->ParentNode == node);
|
IM_ASSERT(node->ChildNodes[1] == NULL || node->ChildNodes[1]->ParentNode == node);
|
||||||
ImGui::BulletText("Pos (%.0f,%.0f), Size (%.0f, %.0f) Ref (%.0f, %.0f)",
|
ImGui::BulletText("Pos (%.0f,%.0f), Size (%.0f, %.0f) Ref (%.0f, %.0f)",
|
||||||
node->Pos.x, node->Pos.y, node->Size.x, node->Size.y, node->SizeRef.x, node->SizeRef.y);
|
node->Pos.x, node->Pos.y, node->Size.x, node->Size.y, node->SizeRef.x, node->SizeRef.y);
|
||||||
|
NodeWindow(node->HostWindow, "HostWindow");
|
||||||
NodeWindow(node->VisibleWindow, "VisibleWindow");
|
NodeWindow(node->VisibleWindow, "VisibleWindow");
|
||||||
ImGui::BulletText("SelectedTabID: 0x%08X, LastFocusedNodeID: 0x%08X", node->SelectedTabID, node->LastFocusedNodeID);
|
ImGui::BulletText("SelectedTabID: 0x%08X, LastFocusedNodeID: 0x%08X", node->SelectedTabID, node->LastFocusedNodeID);
|
||||||
ImGui::BulletText("Misc:%s%s%s%s", node->IsDockSpace() ? " IsDockSpace" : "", node->IsCentralNode() ? " IsCentralNode" : "", (g.FrameCount - node->LastFrameAlive < 2) ? " IsAlive" : "", (g.FrameCount - node->LastFrameActive < 2) ? " IsActive" : "");
|
ImGui::BulletText("Misc:%s%s%s%s", node->IsDockSpace() ? " IsDockSpace" : "", node->IsCentralNode() ? " IsCentralNode" : "", (g.FrameCount - node->LastFrameAlive < 2) ? " IsAlive" : "", (g.FrameCount - node->LastFrameActive < 2) ? " IsActive" : "");
|
||||||
|
@ -1606,7 +1606,7 @@ struct ImGuiTabBar
|
|||||||
{
|
{
|
||||||
ImVector<ImGuiTabItem> Tabs;
|
ImVector<ImGuiTabItem> Tabs;
|
||||||
ImGuiID ID; // Zero for tab-bars used by docking
|
ImGuiID ID; // Zero for tab-bars used by docking
|
||||||
ImGuiID SelectedTabId; // Selected tab
|
ImGuiID SelectedTabId; // Selected tab/window
|
||||||
ImGuiID NextSelectedTabId;
|
ImGuiID NextSelectedTabId;
|
||||||
ImGuiID VisibleTabId; // Can occasionally be != SelectedTabId (e.g. when previewing contents for CTRL+TAB preview)
|
ImGuiID VisibleTabId; // Can occasionally be != SelectedTabId (e.g. when previewing contents for CTRL+TAB preview)
|
||||||
int CurrFrameVisible;
|
int CurrFrameVisible;
|
||||||
@ -1777,6 +1777,7 @@ namespace ImGui
|
|||||||
IMGUI_API void DockContextRebuildNodes(ImGuiContext* ctx);
|
IMGUI_API void DockContextRebuildNodes(ImGuiContext* ctx);
|
||||||
IMGUI_API void DockContextUpdateUndocking(ImGuiContext* ctx);
|
IMGUI_API void DockContextUpdateUndocking(ImGuiContext* ctx);
|
||||||
IMGUI_API void DockContextUpdateDocking(ImGuiContext* ctx);
|
IMGUI_API void DockContextUpdateDocking(ImGuiContext* ctx);
|
||||||
|
IMGUI_API ImGuiID DockContextGenNodeID(ImGuiContext* ctx);
|
||||||
IMGUI_API void DockContextQueueDock(ImGuiContext* ctx, ImGuiWindow* target, ImGuiDockNode* target_node, ImGuiWindow* payload, ImGuiDir split_dir, float split_ratio, bool split_outer);
|
IMGUI_API void DockContextQueueDock(ImGuiContext* ctx, ImGuiWindow* target, ImGuiDockNode* target_node, ImGuiWindow* payload, ImGuiDir split_dir, float split_ratio, bool split_outer);
|
||||||
IMGUI_API void DockContextQueueUndockWindow(ImGuiContext* ctx, ImGuiWindow* window);
|
IMGUI_API void DockContextQueueUndockWindow(ImGuiContext* ctx, ImGuiWindow* window);
|
||||||
IMGUI_API void DockContextQueueUndockNode(ImGuiContext* ctx, ImGuiDockNode* node);
|
IMGUI_API void DockContextQueueUndockNode(ImGuiContext* ctx, ImGuiDockNode* node);
|
||||||
|
Loading…
Reference in New Issue
Block a user