Skip to content

Commit

Permalink
Docking: Amend 24dfebf. Fixed incorrect focus highlight on docking no…
Browse files Browse the repository at this point in the history
…de with nested hierarchies.
  • Loading branch information
ocornut committed Jun 17, 2022
1 parent 5067173 commit 9764adc
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6325,7 +6325,7 @@ void ImGui::UpdateWindowParentAndRootLinks(ImGuiWindow* window, ImGuiWindowFlags
}
if (parent_window && (flags & ImGuiWindowFlags_Popup))
window->RootWindowPopupTree = parent_window->RootWindowPopupTree;
if (parent_window && !(flags & ImGuiWindowFlags_Modal) && (flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Popup)))
if (parent_window && !(flags & ImGuiWindowFlags_Modal) && (flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Popup))) // FIXME: simply use _NoTitleBar ?
window->RootWindowForTitleBarHighlight = parent_window->RootWindowForTitleBarHighlight;
while (window->RootWindowForNav->Flags & ImGuiWindowFlags_NavFlattened)
{
Expand Down Expand Up @@ -15293,6 +15293,21 @@ void ImGui::DockNodeEndAmendTabBar()
End();
}

static bool IsDockNodeTitleBarHighlighted(ImGuiDockNode* node, ImGuiDockNode* root_node, ImGuiWindow* host_window)
{
// CTRL+Tab highlight (only highlighting leaf node, not whole hierarchy)
ImGuiContext& g = *GImGui;
if (g.NavWindowingTarget)
return (g.NavWindowingTarget->DockNode == node);

// FIXME-DOCKING: May want alternative to treat central node void differently? e.g. if (g.NavWindow == host_window)
if (g.NavWindow && g.NavWindow->RootWindowForTitleBarHighlight == host_window->RootWindowDockTree && root_node->LastFocusedNodeId == node->ID)
for (ImGuiDockNode* parent_node = g.NavWindow->RootWindow->DockNode; parent_node != NULL; parent_node = parent_node->HostWindow ? parent_node->HostWindow->RootWindow->DockNode : NULL)
if ((parent_node = ImGui::DockNodeGetRootNode(parent_node)) == root_node)
return true;
return false;
}

// Submit the tab bar corresponding to a dock node and various housekeeping details.
static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_window)
{
Expand All @@ -15308,14 +15323,8 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w
// Decide if we should use a focused title bar color
bool is_focused = false;
ImGuiDockNode* root_node = DockNodeGetRootNode(node);
if (g.NavWindowingTarget)
is_focused = (g.NavWindowingTarget->DockNode == node);
else if (g.NavWindow && g.NavWindow->RootWindowForTitleBarHighlight == host_window->RootWindowDockTree && root_node->LastFocusedNodeId == node->ID)
{
// FIXME-DOCKING: May want alternative to treat central node void differently? e.g. if (g.NavWindow == host_window)
if (g.NavWindow->DockNode && DockNodeIsInHierarchyOf(g.NavWindow->DockNode, root_node)) // Omit child windows injected in window hierarchy
is_focused = true;
}
if (IsDockNodeTitleBarHighlighted(node, root_node, host_window))
is_focused = true;

// Hidden tab bar will show a triangle on the upper-left (in Begin)
if (node->IsHiddenTabBar() || node->IsNoTabBar())
Expand Down

0 comments on commit 9764adc

Please sign in to comment.