Skip to content

Commit 9943137

Browse files
committed
TreeNode: fixed non-opened clipped child node not moving Y2 marker. (#2920)
1 parent ee0d96a commit 9943137

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

imgui.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7649,7 +7649,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
76497649
window->DC.MenuBarAppending = false;
76507650
window->DC.MenuColumns.Update(style.ItemSpacing.x, window_just_activated_by_user);
76517651
window->DC.TreeDepth = 0;
7652-
window->DC.TreeHasStackDataDepthMask = 0x00;
7652+
window->DC.TreeHasStackDataDepthMask = window->DC.TreeRecordsClippedNodesY2Mask = 0x00;
76537653
window->DC.ChildWindows.resize(0);
76547654
window->DC.StateStorage = &window->StateStorage;
76557655
window->DC.CurrentColumns = NULL;

imgui_internal.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -2474,7 +2474,8 @@ struct IMGUI_API ImGuiWindowTempData
24742474
ImVec2 MenuBarOffset; // MenuBarOffset.x is sort of equivalent of a per-layer CursorPos.x, saved/restored as we switch to the menu bar. The only situation when MenuBarOffset.y is > 0 if when (SafeAreaPadding.y > FramePadding.y), often used on TVs.
24752475
ImGuiMenuColumns MenuColumns; // Simplified columns storage for menu items measurement
24762476
int TreeDepth; // Current tree depth.
2477-
ImU32 TreeHasStackDataDepthMask; // Store whether given depth has ImGuiTreeNodeStackData data. Could be turned into a ImU64 if necessary.
2477+
ImU32 TreeHasStackDataDepthMask; // Store whether given depth has ImGuiTreeNodeStackData data. Could be turned into a ImU64 if necessary.
2478+
ImU32 TreeRecordsClippedNodesY2Mask; // Store whether we should keep recording Y2. Cleared when passing clip max. Equivalent TreeHasStackDataDepthMask value should always be set.
24782479
ImVector<ImGuiWindow*> ChildWindows;
24792480
ImGuiStorage* StateStorage; // Current persistent per-window storage (store e.g. tree node open/close state)
24802481
ImGuiOldColumns* CurrentColumns; // Current columns set

imgui_widgets.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -6564,9 +6564,11 @@ static void TreeNodeStoreStackData(ImGuiTreeNodeFlags flags, float x1)
65646564
// Initially I tried to latch value for GetColorU32(ImGuiCol_TreeLines) but it's not a good trade-off for very large trees.
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;
6567-
tree_node_data->DrawLinesTableColumn = draw_lines && g.CurrentTable ? (ImGuiTableColumnIdx)g.CurrentTable->CurrentColumn : -1;
6567+
tree_node_data->DrawLinesTableColumn = (draw_lines && g.CurrentTable) ? (ImGuiTableColumnIdx)g.CurrentTable->CurrentColumn : -1;
65686568
tree_node_data->DrawLinesToNodesY2 = -FLT_MAX;
65696569
window->DC.TreeHasStackDataDepthMask |= (1 << window->DC.TreeDepth);
6570+
if (flags & ImGuiTreeNodeFlags_DrawLinesToNodes)
6571+
window->DC.TreeRecordsClippedNodesY2Mask |= (1 << window->DC.TreeDepth);
65706572
}
65716573

65726574
// When using public API, currently 'id == storage_id' is always true, but we separate the values to facilitate advanced user code doing storage queries outside of UI loop.
@@ -6656,10 +6658,12 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
66566658
const bool is_leaf = (flags & ImGuiTreeNodeFlags_Leaf) != 0;
66576659
if (!is_visible)
66586660
{
6659-
if (draw_tree_lines && (flags & ImGuiTreeNodeFlags_DrawLinesToNodes) && (window->DC.TreeHasStackDataDepthMask & (1 << window->DC.TreeDepth)))
6661+
if ((flags & ImGuiTreeNodeFlags_DrawLinesToNodes) && (window->DC.TreeRecordsClippedNodesY2Mask & (1 << (window->DC.TreeDepth - 1))))
66606662
{
66616663
ImGuiTreeNodeStackData* parent_data = &g.TreeNodeStack.Data[g.TreeNodeStack.Size - 1];
66626664
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.
6665+
if (frame_bb.Min.y >= window->ClipRect.Max.y)
6666+
window->DC.TreeRecordsClippedNodesY2Mask &= ~(1 << (window->DC.TreeDepth - 1)); // Done
66636667
}
66646668
if (is_open && store_tree_node_stack_data)
66656669
TreeNodeStoreStackData(flags, text_pos.x - text_offset_x); // Call before TreePushOverrideID()

0 commit comments

Comments
 (0)