Skip to content

Commit 266b837

Browse files
committed
TreeNode, Tables: fixed ImGuiTreeNodeFlags_DrawLinesXXX feature when TreePop() is called from a different column. (#2920)
1 parent 75001fa commit 266b837

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

imgui_internal.h

+8-5
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.
@@ -1315,6 +1319,7 @@ struct ImGuiTreeNodeStackData
13151319
ImRect NavRect; // Used for nav landing
13161320
float DrawLinesX1;
13171321
float DrawLinesY2;
1322+
ImGuiTableColumnIdx DrawLinesTableColumn;
13181323
};
13191324

13201325
// sizeof() = 20
@@ -2942,11 +2947,7 @@ struct IMGUI_API ImGuiTabBar
29422947
//-----------------------------------------------------------------------------
29432948

29442949
#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;
2950+
#define IMGUI_TABLE_MAX_COLUMNS 512 // Arbitrary "safety" maximum, may be lifted in the future if needed. Must fit in ImGuiTableColumnIdx/ImGuiTableDrawChannelIdx.
29502951

29512952
// [Internal] sizeof() ~ 112
29522953
// We use the terminology "Enabled" to refer to a column that is not Hidden by user/api.
@@ -3641,6 +3642,8 @@ namespace ImGui
36413642
IMGUI_API float TableGetHeaderAngledMaxLabelWidth();
36423643
IMGUI_API void TablePushBackgroundChannel();
36433644
IMGUI_API void TablePopBackgroundChannel();
3645+
IMGUI_API void TablePushColumnChannel(int column_n);
3646+
IMGUI_API void TablePopColumnChannel();
36443647
IMGUI_API void TableAngledHeadersRowEx(ImGuiID row_id, float angle, float max_label_width, const ImGuiTableHeaderData* data, int data_count);
36453648

36463649
// Tables: Internals

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)
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

+7-1
Original file line numberDiff line numberDiff line change
@@ -6569,7 +6569,9 @@ 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;
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;
65736575
tree_node_data->DrawLinesY2 = -FLT_MAX;
65746576
window->DC.TreeHasStackDataDepthMask |= (1 << window->DC.TreeDepth);
65756577
}
@@ -6926,7 +6928,11 @@ void ImGui::TreePop()
69266928
if (y1 < y2)
69276929
{
69286930
float x = ImTrunc(data->DrawLinesX1);
6931+
if (data->DrawLinesTableColumn != -1)
6932+
TablePushColumnChannel(data->DrawLinesTableColumn);
69296933
window->DrawList->AddLine(ImVec2(x, y1), ImVec2(x, y2), GetColorU32(ImGuiCol_TreeLines), g.Style.TreeLinesSize);
6934+
if (data->DrawLinesTableColumn != -1)
6935+
TablePopColumnChannel();
69306936
}
69316937
}
69326938
g.TreeNodeStack.pop_back();

0 commit comments

Comments
 (0)