Skip to content

Commit 5311253

Browse files
committed
TreeNode: ImGuiTreeNodeFlags_DrawLinesFull uses ToNodes Y2 when they are close (using a threshold). (#2920)
1 parent ed50bb1 commit 5311253

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

imgui.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1217,8 +1217,8 @@ enum ImGuiTreeNodeFlags_
12171217
// [EXPERIMENTAL] Draw lines connecting TreeNode hierarchy. Discuss in GitHub issue #2920.
12181218
// Default value is pulled from style.TreeLinesFlags. May be overridden in TreeNode calls.
12191219
ImGuiTreeNodeFlags_DrawLinesNone = 1 << 18, // No lines drawn
1220-
ImGuiTreeNodeFlags_DrawLinesFull = 1 << 19, // Horizontal lines to child nodes. Vertical line drawn down to TreePop() position: cover full contents.
1221-
ImGuiTreeNodeFlags_DrawLinesToNodes = 1 << 20, // Horizontal lines to child nodes. Vertical line drawn down to bottom-most child node. A little bit slower.
1220+
ImGuiTreeNodeFlags_DrawLinesFull = 1 << 19, // Horizontal lines to child nodes. Vertical line drawn down to TreePop() position: cover full contents. Faster (for large trees).
1221+
ImGuiTreeNodeFlags_DrawLinesToNodes = 1 << 20, // Horizontal lines to child nodes. Vertical line drawn down to bottom-most child node. Slower (for large trees).
12221222

12231223
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
12241224
ImGuiTreeNodeFlags_AllowItemOverlap = ImGuiTreeNodeFlags_AllowOverlap, // Renamed in 1.89.7

imgui_internal.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ struct ImGuiTreeNodeStackData
12991299
ImGuiItemFlags ItemFlags; // Used for nav landing
13001300
ImRect NavRect; // Used for nav landing
13011301
float DrawLinesX1;
1302-
float DrawLinesY2;
1302+
float DrawLinesToNodesY2;
13031303
ImGuiTableColumnIdx DrawLinesTableColumn;
13041304
};
13051305

imgui_widgets.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -6565,7 +6565,7 @@ static void TreeNodeStoreStackData(ImGuiTreeNodeFlags flags, float x1)
65656565
const bool draw_lines = (flags & (ImGuiTreeNodeFlags_DrawLinesFull | ImGuiTreeNodeFlags_DrawLinesToNodes)) != 0;
65666566
tree_node_data->DrawLinesX1 = draw_lines ? (x1 + g.FontSize * 0.5f + g.Style.FramePadding.x) : +FLT_MAX;
65676567
tree_node_data->DrawLinesTableColumn = draw_lines && g.CurrentTable ? (ImGuiTableColumnIdx)g.CurrentTable->CurrentColumn : -1;
6568-
tree_node_data->DrawLinesY2 = -FLT_MAX;
6568+
tree_node_data->DrawLinesToNodesY2 = -FLT_MAX;
65696569
window->DC.TreeHasStackDataDepthMask |= (1 << window->DC.TreeDepth);
65706570
}
65716571

@@ -6659,7 +6659,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
66596659
if (draw_tree_lines && (flags & ImGuiTreeNodeFlags_DrawLinesToNodes) && (window->DC.TreeHasStackDataDepthMask & (1 << window->DC.TreeDepth)))
66606660
{
66616661
ImGuiTreeNodeStackData* parent_data = &g.TreeNodeStack.Data[g.TreeNodeStack.Size - 1];
6662-
parent_data->DrawLinesY2 = ImMax(parent_data->DrawLinesY2, window->DC.CursorPos.y); // Don't need to aim to mid Y position as we are clipped anyway.
6662+
parent_data->DrawLinesToNodesY2 = ImMax(parent_data->DrawLinesToNodesY2, window->DC.CursorPos.y); // Don't need to aim to mid Y position as we are clipped anyway.
66636663
}
66646664
if (is_open && store_tree_node_stack_data)
66656665
TreeNodeStoreStackData(flags, text_pos.x - text_offset_x); // Call before TreePushOverrideID()
@@ -6863,7 +6863,7 @@ void ImGui::TreeNodeDrawLineToChildNode(const ImVec2& target_pos)
68636863
float x1 = ImTrunc(parent_data->DrawLinesX1);
68646864
float x2 = ImTrunc(target_pos.x - g.Style.ItemInnerSpacing.x);
68656865
float y = ImTrunc(target_pos.y);
6866-
parent_data->DrawLinesY2 = ImMax(parent_data->DrawLinesY2, y);
6866+
parent_data->DrawLinesToNodesY2 = ImMax(parent_data->DrawLinesToNodesY2, y);
68676867
if (x1 < x2)
68686868
window->DrawList->AddLine(ImVec2(x1, y), ImVec2(x2, y), GetColorU32(ImGuiCol_TreeLines), g.Style.TreeLinesSize);
68696869
}
@@ -6916,7 +6916,13 @@ void ImGui::TreePop()
69166916
{
69176917
// Draw vertical line of the hierarchy
69186918
float y1 = ImMax(data->NavRect.Max.y, window->ClipRect.Min.y);
6919-
float y2 = (data->TreeFlags & ImGuiTreeNodeFlags_DrawLinesToNodes) ? data->DrawLinesY2 : ImTrunc(window->DC.CursorPos.y - g.Style.ItemSpacing.y - g.FontSize * 0.5f);
6919+
float y2 = data->DrawLinesToNodesY2;
6920+
if (data->TreeFlags & ImGuiTreeNodeFlags_DrawLinesFull)
6921+
{
6922+
float y2_full = ImTrunc(window->DC.CursorPos.y - g.Style.ItemSpacing.y - g.FontSize * 0.5f);
6923+
if (y2 + g.Style.ItemSpacing.y < y2_full) // FIXME: threshold to use ToNodes Y2 instead of Full Y2 when close by ItemSpacing.y
6924+
y2 = y2_full;
6925+
}
69206926
y2 = ImMin(y2, window->ClipRect.Max.y);
69216927
if (y1 < y2)
69226928
{

0 commit comments

Comments
 (0)