Skip to content

Commit f4d9359

Browse files
committed
Merge branch 'master' into docking
2 parents 06c2c9f + 9943137 commit f4d9359

File tree

6 files changed

+101
-35
lines changed

6 files changed

+101
-35
lines changed

docs/CHANGELOG.txt

+8-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ Other changes:
5555
- Windows: loosened code to allow hovering of resize grips, borders, and table
5656
borders while hovering a sibling child window, so that the code in master matches
5757
one in docking (they accidentally diverged). (#8554)
58-
- TreeNode: added flags to draw tree hierarchy outlines linking parent
59-
and tree nodes: (#2920)
58+
- TreeNode: added experimental flags to draw tree hierarchy outlines linking
59+
parent and tree nodes: (#2920)
6060
- ImGuiTreeNodeFlags_DrawLinesNone: No lines drawn (default value in style.TreeLinesFlags).
6161
- ImGuiTreeNodeFlags_DrawLinesFull: Horizontal lines to child nodes. Vertical line drawn down to TreePop() position: cover full contents.
6262
- ImGuiTreeNodeFlags_DrawLinesToNodes: Horizontal lines to child nodes. Vertical line drawn down to bottom-most child node.
@@ -69,6 +69,12 @@ Other changes:
6969
nodes in unusual ways, using indent to create tree-looking structures, etc.)
7070
and the feature may not accurately represent them in every cases.
7171
- The feature adds a little cost as extra data needs to be stored.
72+
(ImGuiTreeNodeFlags_DrawLinesToNodes is slower than ImGuiTreeNodeFlags_DrawLinesFull
73+
which may be meaningful on very large trees, as it needs to record bottom-most
74+
Y position even for clipped nodes).
75+
- The feature is unlikely to ever work properly when using a coarse clipper
76+
such as ImGuiListClipper.
77+
- TreeNode: fixed incorrect clipping of arrow/bullet when using ImGuiTreeNodeFlags_SpanAllColumns.
7278
- Nav: fixed assertion when holding gamepad FaceLeft/West button to open
7379
CTRL+Tab windowing + pressing a keyboard key. (#8525)
7480
- Error Handling: added better error report and recovery for extraneous

imgui.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8155,7 +8155,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
81558155
window->DC.MenuBarAppending = false;
81568156
window->DC.MenuColumns.Update(style.ItemSpacing.x, window_just_activated_by_user);
81578157
window->DC.TreeDepth = 0;
8158-
window->DC.TreeHasStackDataDepthMask = 0x00;
8158+
window->DC.TreeHasStackDataDepthMask = window->DC.TreeRecordsClippedNodesY2Mask = 0x00;
81598159
window->DC.ChildWindows.resize(0);
81608160
window->DC.StateStorage = &window->StateStorage;
81618161
window->DC.CurrentColumns = NULL;

imgui.h

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

12621262
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
12631263
ImGuiTreeNodeFlags_AllowItemOverlap = ImGuiTreeNodeFlags_AllowOverlap, // Renamed in 1.89.7

imgui_internal.h

+12-7
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ typedef int ImGuiTooltipFlags; // -> enum ImGuiTooltipFlags_ // F
212212
typedef int ImGuiTypingSelectFlags; // -> enum ImGuiTypingSelectFlags_ // Flags: for GetTypingSelectRequest()
213213
typedef int ImGuiWindowRefreshFlags; // -> enum ImGuiWindowRefreshFlags_ // Flags: for SetNextWindowRefreshPolicy()
214214

215+
// Table column indexing
216+
typedef ImS16 ImGuiTableColumnIdx;
217+
typedef ImU16 ImGuiTableDrawChannelIdx;
218+
215219
//-----------------------------------------------------------------------------
216220
// [SECTION] Context pointer
217221
// See implementation of this variable in imgui.cpp for comments and details.
@@ -1314,7 +1318,8 @@ struct ImGuiTreeNodeStackData
13141318
ImGuiItemFlags ItemFlags; // Used for nav landing
13151319
ImRect NavRect; // Used for nav landing
13161320
float DrawLinesX1;
1317-
float DrawLinesY2;
1321+
float DrawLinesToNodesY2;
1322+
ImGuiTableColumnIdx DrawLinesTableColumn;
13181323
};
13191324

13201325
// sizeof() = 20
@@ -2681,7 +2686,8 @@ struct IMGUI_API ImGuiWindowTempData
26812686
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.
26822687
ImGuiMenuColumns MenuColumns; // Simplified columns storage for menu items measurement
26832688
int TreeDepth; // Current tree depth.
2684-
ImU32 TreeHasStackDataDepthMask; // Store whether given depth has ImGuiTreeNodeStackData data. Could be turned into a ImU64 if necessary.
2689+
ImU32 TreeHasStackDataDepthMask; // Store whether given depth has ImGuiTreeNodeStackData data. Could be turned into a ImU64 if necessary.
2690+
ImU32 TreeRecordsClippedNodesY2Mask; // Store whether we should keep recording Y2. Cleared when passing clip max. Equivalent TreeHasStackDataDepthMask value should always be set.
26852691
ImVector<ImGuiWindow*> ChildWindows;
26862692
ImGuiStorage* StateStorage; // Current persistent per-window storage (store e.g. tree node open/close state)
26872693
ImGuiOldColumns* CurrentColumns; // Current columns set
@@ -2942,11 +2948,7 @@ struct IMGUI_API ImGuiTabBar
29422948
//-----------------------------------------------------------------------------
29432949

29442950
#define IM_COL32_DISABLE IM_COL32(0,0,0,1) // Special sentinel code which cannot be used as a regular color.
2945-
#define IMGUI_TABLE_MAX_COLUMNS 512 // May be further lifted
2946-
2947-
// Our current column maximum is 64 but we may raise that in the future.
2948-
typedef ImS16 ImGuiTableColumnIdx;
2949-
typedef ImU16 ImGuiTableDrawChannelIdx;
2951+
#define IMGUI_TABLE_MAX_COLUMNS 512 // Arbitrary "safety" maximum, may be lifted in the future if needed. Must fit in ImGuiTableColumnIdx/ImGuiTableDrawChannelIdx.
29502952

29512953
// [Internal] sizeof() ~ 112
29522954
// We use the terminology "Enabled" to refer to a column that is not Hidden by user/api.
@@ -3641,6 +3643,8 @@ namespace ImGui
36413643
IMGUI_API float TableGetHeaderAngledMaxLabelWidth();
36423644
IMGUI_API void TablePushBackgroundChannel();
36433645
IMGUI_API void TablePopBackgroundChannel();
3646+
IMGUI_API void TablePushColumnChannel(int column_n);
3647+
IMGUI_API void TablePopColumnChannel();
36443648
IMGUI_API void TableAngledHeadersRowEx(ImGuiID row_id, float angle, float max_label_width, const ImGuiTableHeaderData* data, int data_count);
36453649

36463650
// Tables: Internals
@@ -3769,6 +3773,7 @@ namespace ImGui
37693773
// Widgets: Tree Nodes
37703774
IMGUI_API bool TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end = NULL);
37713775
IMGUI_API void TreeNodeDrawLineToChildNode(const ImVec2& target_pos);
3776+
IMGUI_API void TreeNodeDrawLineToTreePop(const ImGuiTreeNodeStackData* data);
37723777
IMGUI_API void TreePushOverrideID(ImGuiID id);
37733778
IMGUI_API bool TreeNodeGetOpen(ImGuiID storage_id);
37743779
IMGUI_API void TreeNodeSetOpen(ImGuiID storage_id, bool open);

imgui_tables.cpp

+30-1
Original file line numberDiff line numberDiff line change
@@ -2193,6 +2193,7 @@ void ImGui::TableBeginCell(ImGuiTable* table, int column_n)
21932193
g.LastItemData.StatusFlags = 0;
21942194
}
21952195

2196+
// Also see TablePushColumnChannel()
21962197
if (table->Flags & ImGuiTableFlags_NoClip)
21972198
{
21982199
// FIXME: if we end up drawing all borders/bg in EndTable, could remove this and just assert that channel hasn't changed.
@@ -2466,10 +2467,38 @@ void ImGui::TablePopBackgroundChannel()
24662467
ImGuiContext& g = *GImGui;
24672468
ImGuiWindow* window = g.CurrentWindow;
24682469
ImGuiTable* table = g.CurrentTable;
2469-
ImGuiTableColumn* column = &table->Columns[table->CurrentColumn];
24702470

24712471
// Optimization: avoid PopClipRect() + SetCurrentChannel()
24722472
SetWindowClipRectBeforeSetChannel(window, table->HostBackupInnerClipRect);
2473+
table->DrawSplitter->SetCurrentChannel(window->DrawList, table->Columns[table->CurrentColumn].DrawChannelCurrent);
2474+
}
2475+
2476+
// Also see TableBeginCell()
2477+
void ImGui::TablePushColumnChannel(int column_n)
2478+
{
2479+
ImGuiContext& g = *GImGui;
2480+
ImGuiTable* table = g.CurrentTable;
2481+
2482+
// Optimization: avoid SetCurrentChannel() + PushClipRect()
2483+
if (table->Flags & ImGuiTableFlags_NoClip)
2484+
return;
2485+
ImGuiWindow* window = g.CurrentWindow;
2486+
const ImGuiTableColumn* column = &table->Columns[column_n];
2487+
SetWindowClipRectBeforeSetChannel(window, column->ClipRect);
2488+
table->DrawSplitter->SetCurrentChannel(window->DrawList, column->DrawChannelCurrent);
2489+
}
2490+
2491+
void ImGui::TablePopColumnChannel()
2492+
{
2493+
ImGuiContext& g = *GImGui;
2494+
ImGuiTable* table = g.CurrentTable;
2495+
2496+
// Optimization: avoid PopClipRect() + SetCurrentChannel()
2497+
if ((table->Flags & ImGuiTableFlags_NoClip) || (table->CurrentColumn == -1)) // Calling TreePop() after TableNextRow() is supported.
2498+
return;
2499+
ImGuiWindow* window = g.CurrentWindow;
2500+
const ImGuiTableColumn* column = &table->Columns[table->CurrentColumn];
2501+
SetWindowClipRectBeforeSetChannel(window, column->ClipRect);
24732502
table->DrawSplitter->SetCurrentChannel(window->DrawList, column->DrawChannelCurrent);
24742503
}
24752504

imgui_widgets.cpp

+48-22
Original file line numberDiff line numberDiff line change
@@ -6569,9 +6569,13 @@ static void TreeNodeStoreStackData(ImGuiTreeNodeFlags flags, float x1)
65696569
tree_node_data->NavRect = g.LastItemData.NavRect;
65706570

65716571
// Initially I tried to latch value for GetColorU32(ImGuiCol_TreeLines) but it's not a good trade-off for very large trees.
6572-
tree_node_data->DrawLinesX1 = (flags & (ImGuiTreeNodeFlags_DrawLinesFull | ImGuiTreeNodeFlags_DrawLinesToNodes)) ? (x1 + g.FontSize * 0.5f + g.Style.FramePadding.x) : +FLT_MAX;
6573-
tree_node_data->DrawLinesY2 = -FLT_MAX;
6572+
const bool draw_lines = (flags & (ImGuiTreeNodeFlags_DrawLinesFull | ImGuiTreeNodeFlags_DrawLinesToNodes)) != 0;
6573+
tree_node_data->DrawLinesX1 = draw_lines ? (x1 + g.FontSize * 0.5f + g.Style.FramePadding.x) : +FLT_MAX;
6574+
tree_node_data->DrawLinesTableColumn = (draw_lines && g.CurrentTable) ? (ImGuiTableColumnIdx)g.CurrentTable->CurrentColumn : -1;
6575+
tree_node_data->DrawLinesToNodesY2 = -FLT_MAX;
65746576
window->DC.TreeHasStackDataDepthMask |= (1 << window->DC.TreeDepth);
6577+
if (flags & ImGuiTreeNodeFlags_DrawLinesToNodes)
6578+
window->DC.TreeRecordsClippedNodesY2Mask |= (1 << window->DC.TreeDepth);
65756579
}
65766580

65776581
// 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.
@@ -6661,10 +6665,12 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
66616665
const bool is_leaf = (flags & ImGuiTreeNodeFlags_Leaf) != 0;
66626666
if (!is_visible)
66636667
{
6664-
if (draw_tree_lines && (flags & ImGuiTreeNodeFlags_DrawLinesToNodes) && (window->DC.TreeHasStackDataDepthMask & (1 << window->DC.TreeDepth)))
6668+
if ((flags & ImGuiTreeNodeFlags_DrawLinesToNodes) && (window->DC.TreeRecordsClippedNodesY2Mask & (1 << (window->DC.TreeDepth - 1))))
66656669
{
66666670
ImGuiTreeNodeStackData* parent_data = &g.TreeNodeStack.Data[g.TreeNodeStack.Size - 1];
6667-
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.
6671+
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.
6672+
if (frame_bb.Min.y >= window->ClipRect.Max.y)
6673+
window->DC.TreeRecordsClippedNodesY2Mask &= ~(1 << (window->DC.TreeDepth - 1)); // Done
66686674
}
66696675
if (is_open && store_tree_node_stack_data)
66706676
TreeNodeStoreStackData(flags, text_pos.x - text_offset_x); // Call before TreePushOverrideID()
@@ -6801,6 +6807,8 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
68016807
const ImU32 bg_col = GetColorU32((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
68026808
RenderFrame(frame_bb.Min, frame_bb.Max, bg_col, true, style.FrameRounding);
68036809
RenderNavCursor(frame_bb, id, nav_render_cursor_flags);
6810+
if (span_all_columns && !span_all_columns_label)
6811+
TablePopBackgroundChannel();
68046812
if (flags & ImGuiTreeNodeFlags_Bullet)
68056813
RenderBullet(window->DrawList, ImVec2(text_pos.x - text_offset_x * 0.60f, text_pos.y + g.FontSize * 0.5f), text_col);
68066814
else if (!is_leaf)
@@ -6821,6 +6829,8 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
68216829
RenderFrame(frame_bb.Min, frame_bb.Max, bg_col, false);
68226830
}
68236831
RenderNavCursor(frame_bb, id, nav_render_cursor_flags);
6832+
if (span_all_columns && !span_all_columns_label)
6833+
TablePopBackgroundChannel();
68246834
if (flags & ImGuiTreeNodeFlags_Bullet)
68256835
RenderBullet(window->DrawList, ImVec2(text_pos.x - text_offset_x * 0.5f, text_pos.y + g.FontSize * 0.5f), text_col);
68266836
else if (!is_leaf)
@@ -6832,9 +6842,6 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
68326842
if (draw_tree_lines)
68336843
TreeNodeDrawLineToChildNode(ImVec2(text_pos.x - text_offset_x + padding.x, text_pos.y + g.FontSize * 0.5f));
68346844

6835-
if (span_all_columns && !span_all_columns_label)
6836-
TablePopBackgroundChannel();
6837-
68386845
// Label
68396846
if (display_frame)
68406847
RenderTextClipped(text_pos, frame_bb.Max, label, label_end, &label_size);
@@ -6867,11 +6874,38 @@ void ImGui::TreeNodeDrawLineToChildNode(const ImVec2& target_pos)
68676874
float x1 = ImTrunc(parent_data->DrawLinesX1);
68686875
float x2 = ImTrunc(target_pos.x - g.Style.ItemInnerSpacing.x);
68696876
float y = ImTrunc(target_pos.y);
6870-
parent_data->DrawLinesY2 = ImMax(parent_data->DrawLinesY2, y);
6877+
parent_data->DrawLinesToNodesY2 = ImMax(parent_data->DrawLinesToNodesY2, y);
68716878
if (x1 < x2)
68726879
window->DrawList->AddLine(ImVec2(x1, y), ImVec2(x2, y), GetColorU32(ImGuiCol_TreeLines), g.Style.TreeLinesSize);
68736880
}
68746881

6882+
// Draw vertical line of the hierarchy
6883+
void ImGui::TreeNodeDrawLineToTreePop(const ImGuiTreeNodeStackData* data)
6884+
{
6885+
ImGuiContext& g = *GImGui;
6886+
ImGuiWindow* window = g.CurrentWindow;
6887+
float y1 = ImMax(data->NavRect.Max.y, window->ClipRect.Min.y);
6888+
float y2 = data->DrawLinesToNodesY2;
6889+
if (data->TreeFlags & ImGuiTreeNodeFlags_DrawLinesFull)
6890+
{
6891+
float y2_full = window->DC.CursorPos.y;
6892+
if (g.CurrentTable)
6893+
y2_full = ImMax(g.CurrentTable->RowPosY2, y2_full);
6894+
y2_full = ImTrunc(y2_full - g.Style.ItemSpacing.y - g.FontSize * 0.5f);
6895+
if (y2 + g.Style.ItemSpacing.y < y2_full) // FIXME: threshold to use ToNodes Y2 instead of Full Y2 when close by ItemSpacing.y
6896+
y2 = y2_full;
6897+
}
6898+
y2 = ImMin(y2, window->ClipRect.Max.y);
6899+
if (y2 <= y1)
6900+
return;
6901+
float x = ImTrunc(data->DrawLinesX1);
6902+
if (data->DrawLinesTableColumn != -1)
6903+
TablePushColumnChannel(data->DrawLinesTableColumn);
6904+
window->DrawList->AddLine(ImVec2(x, y1), ImVec2(x, y2), GetColorU32(ImGuiCol_TreeLines), g.Style.TreeLinesSize);
6905+
if (data->DrawLinesTableColumn != -1)
6906+
TablePopColumnChannel();
6907+
}
6908+
68756909
void ImGui::TreePush(const char* str_id)
68766910
{
68776911
ImGuiWindow* window = GetCurrentWindow();
@@ -6910,24 +6944,16 @@ void ImGui::TreePop()
69106944
{
69116945
const ImGuiTreeNodeStackData* data = &g.TreeNodeStack.Data[g.TreeNodeStack.Size - 1];
69126946
IM_ASSERT(data->ID == window->IDStack.back());
6947+
6948+
// Handle Left arrow to move to parent tree node (when ImGuiTreeNodeFlags_NavLeftJumpsBackHere is enabled)
69136949
if (data->TreeFlags & ImGuiTreeNodeFlags_NavLeftJumpsBackHere)
6914-
{
6915-
// Handle Left arrow to move to parent tree node (when ImGuiTreeNodeFlags_NavLeftJumpsBackHere is enabled)
69166950
if (g.NavIdIsAlive && g.NavMoveDir == ImGuiDir_Left && g.NavWindow == window && NavMoveRequestButNoResultYet())
69176951
NavMoveRequestResolveWithPastTreeNode(&g.NavMoveResultLocal, data);
6918-
}
6952+
6953+
// Draw hierarchy lines
69196954
if (data->DrawLinesX1 != +FLT_MAX && window->DC.CursorPos.y >= window->ClipRect.Min.y)
6920-
{
6921-
// Draw vertical line of the hierarchy
6922-
float y1 = ImMax(data->NavRect.Max.y, window->ClipRect.Min.y);
6923-
float y2 = (data->TreeFlags & ImGuiTreeNodeFlags_DrawLinesToNodes) ? data->DrawLinesY2 : ImTrunc(window->DC.CursorPos.y - g.Style.ItemSpacing.y - g.FontSize * 0.5f);
6924-
y2 = ImMin(y2, window->ClipRect.Max.y);
6925-
if (y1 < y2)
6926-
{
6927-
float x = ImTrunc(data->DrawLinesX1);
6928-
window->DrawList->AddLine(ImVec2(x, y1), ImVec2(x, y2), GetColorU32(ImGuiCol_TreeLines), g.Style.TreeLinesSize);
6929-
}
6930-
}
6955+
TreeNodeDrawLineToTreePop(data);
6956+
69316957
g.TreeNodeStack.pop_back();
69326958
window->DC.TreeHasStackDataDepthMask &= ~tree_depth_mask;
69336959
}

0 commit comments

Comments
 (0)