1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-16 12:03:27 +01:00

Internals: Docking: make DockContextFindNodeByID() more visible (instead of DockBuilderGetNode)

+ using defines for channel changes.
This commit is contained in:
ocornut 2022-08-03 14:37:35 +02:00
parent cb8ead1f71
commit 28a123ca47
2 changed files with 15 additions and 12 deletions

View File

@ -6179,14 +6179,14 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar
// Render, for docked windows and host windows we ensure bg goes before decorations
ImDrawList* bg_draw_list = window->DockIsActive ? window->DockNode->HostWindow->DrawList : window->DrawList;
if (window->DockIsActive || (flags & ImGuiWindowFlags_DockNodeHost))
bg_draw_list->ChannelsSetCurrent(0);
bg_draw_list->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_BG);
if (window->DockIsActive)
window->DockNode->LastBgColor = bg_col;
bg_draw_list->AddRectFilled(window->Pos + ImVec2(0, window->TitleBarHeight()), window->Pos + window->Size, bg_col, window_rounding, (flags & ImGuiWindowFlags_NoTitleBar) ? 0 : ImDrawFlags_RoundCornersBottom);
if (window->DockIsActive || (flags & ImGuiWindowFlags_DockNodeHost))
bg_draw_list->ChannelsSetCurrent(1);
bg_draw_list->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_FG);
}
if (window->DockIsActive)
window->DockNode->IsBgDrawnThisFrame = true;
@ -6601,7 +6601,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
if (flags & ImGuiWindowFlags_DockNodeHost)
{
window->DrawList->ChannelsSplit(2);
window->DrawList->ChannelsSetCurrent(1); // Render decorations on channel 1 as we will render the backgrounds manually later
window->DrawList->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_FG); // Render decorations on channel 1 as we will render the backgrounds manually later
}
// Restore buffer capacity when woken from a compacted state, to avoid
@ -13766,7 +13766,6 @@ namespace ImGui
static void DockContextProcessUndockWindow(ImGuiContext* ctx, ImGuiWindow* window, bool clear_persistent_docking_ref = true);
static void DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node);
static void DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx);
static ImGuiDockNode* DockContextFindNodeByID(ImGuiContext* ctx, ImGuiID id);
static ImGuiDockNode* DockContextBindNodeToWindow(ImGuiContext* ctx, ImGuiWindow* window);
static void DockContextBuildNodesFromSettings(ImGuiContext* ctx, ImGuiDockNodeSettings* node_settings_array, int node_settings_count);
static void DockContextBuildAddWindowsToNodes(ImGuiContext* ctx, ImGuiID root_id); // Use root_id==0 to add all
@ -13981,12 +13980,12 @@ void ImGui::DockContextEndFrame(ImGuiContext* ctx)
{
ImRect bg_rect(node->Pos + ImVec2(0.0f, GetFrameHeight()), node->Pos + node->Size);
ImDrawFlags bg_rounding_flags = CalcRoundingFlagsForRectInRect(bg_rect, node->HostWindow->Rect(), DOCKING_SPLITTER_SIZE);
node->HostWindow->DrawList->ChannelsSetCurrent(0);
node->HostWindow->DrawList->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_BG);
node->HostWindow->DrawList->AddRectFilled(bg_rect.Min, bg_rect.Max, node->LastBgColor, node->HostWindow->WindowRounding, bg_rounding_flags);
}
}
static ImGuiDockNode* ImGui::DockContextFindNodeByID(ImGuiContext* ctx, ImGuiID id)
ImGuiDockNode* ImGui::DockContextFindNodeByID(ImGuiContext* ctx, ImGuiID id)
{
return (ImGuiDockNode*)ctx->DockContext.Nodes.GetVoidPtr(id);
}
@ -15174,7 +15173,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node)
// Update position/size, process and draw resizing splitters
if (node->IsRootNode() && host_window)
{
host_window->DrawList->ChannelsSetCurrent(1);
host_window->DrawList->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_FG);
DockNodeTreeUpdatePosSize(node, host_window->Pos, host_window->Size);
DockNodeTreeUpdateSplitter(node);
}
@ -15182,7 +15181,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node)
// Draw empty node background (currently can only be the Central Node)
if (host_window && node->IsEmpty() && node->IsVisible)
{
host_window->DrawList->ChannelsSetCurrent(0);
host_window->DrawList->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_BG);
node->LastBgColor = (node_flags & ImGuiDockNodeFlags_PassthruCentralNode) ? 0 : GetColorU32(ImGuiCol_DockingEmptyBg);
if (node->LastBgColor != 0)
host_window->DrawList->AddRectFilled(node->Pos, node->Pos + node->Size, node->LastBgColor);
@ -15195,7 +15194,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node)
const bool render_dockspace_bg = node->IsRootNode() && host_window && (node_flags & ImGuiDockNodeFlags_PassthruCentralNode) != 0;
if (render_dockspace_bg && node->IsVisible)
{
host_window->DrawList->ChannelsSetCurrent(0);
host_window->DrawList->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_BG);
if (central_node_hole)
RenderRectFilledWithHole(host_window->DrawList, node->Rect(), central_node->Rect(), GetColorU32(ImGuiCol_WindowBg), 0.0f);
else
@ -15204,7 +15203,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node)
// Draw and populate Tab Bar
if (host_window)
host_window->DrawList->ChannelsSetCurrent(1);
host_window->DrawList->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_FG);
if (host_window && node->Windows.Size > 0)
{
DockNodeUpdateTabBar(node, host_window);
@ -15240,12 +15239,12 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node)
// Render outer borders last (after the tab bar)
if (node->IsRootNode())
{
host_window->DrawList->ChannelsSetCurrent(1);
host_window->DrawList->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_FG);
RenderWindowOuterBorders(host_window);
}
// Further rendering (= hosted windows background) will be drawn on layer 0
host_window->DrawList->ChannelsSetCurrent(0);
host_window->DrawList->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_BG);
}
// End host window

View File

@ -1448,6 +1448,9 @@ struct ImGuiOldColumns
// [SECTION] Docking support
//-----------------------------------------------------------------------------
#define DOCKING_HOST_DRAW_CHANNEL_BG 0 // Dock host: background fill
#define DOCKING_HOST_DRAW_CHANNEL_FG 1 // Dock host: decorations and contents
#ifdef IMGUI_HAS_DOCK
// Extend ImGuiDockNodeFlags_
@ -2966,6 +2969,7 @@ namespace ImGui
IMGUI_API void DockContextQueueUndockWindow(ImGuiContext* ctx, ImGuiWindow* window);
IMGUI_API void DockContextQueueUndockNode(ImGuiContext* ctx, ImGuiDockNode* node);
IMGUI_API bool DockContextCalcDropPosForDocking(ImGuiWindow* target, ImGuiDockNode* target_node, ImGuiWindow* payload, ImGuiDir split_dir, bool split_outer, ImVec2* out_pos);
IMGUI_API ImGuiDockNode*DockContextFindNodeByID(ImGuiContext* ctx, ImGuiID id);
IMGUI_API bool DockNodeBeginAmendTabBar(ImGuiDockNode* node);
IMGUI_API void DockNodeEndAmendTabBar();
inline ImGuiDockNode* DockNodeGetRootNode(ImGuiDockNode* node) { while (node->ParentNode) node = node->ParentNode; return node; }