Skip to content

Commit ed50bb1

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

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
@@ -206,6 +206,10 @@ typedef int ImGuiTooltipFlags; // -> enum ImGuiTooltipFlags_ // F
206206
typedef int ImGuiTypingSelectFlags; // -> enum ImGuiTypingSelectFlags_ // Flags: for GetTypingSelectRequest()
207207
typedef int ImGuiWindowRefreshFlags; // -> enum ImGuiWindowRefreshFlags_ // Flags: for SetNextWindowRefreshPolicy()
208208

209+
// Table column indexing
210+
typedef ImS16 ImGuiTableColumnIdx;
211+
typedef ImU16 ImGuiTableDrawChannelIdx;
212+
209213
//-----------------------------------------------------------------------------
210214
// [SECTION] Context pointer
211215
// See implementation of this variable in imgui.cpp for comments and details.
@@ -1296,6 +1300,7 @@ struct ImGuiTreeNodeStackData
12961300
ImRect NavRect; // Used for nav landing
12971301
float DrawLinesX1;
12981302
float DrawLinesY2;
1303+
ImGuiTableColumnIdx DrawLinesTableColumn;
12991304
};
13001305

13011306
// sizeof() = 20
@@ -2704,11 +2709,7 @@ struct IMGUI_API ImGuiTabBar
27042709
//-----------------------------------------------------------------------------
27052710

27062711
#define IM_COL32_DISABLE IM_COL32(0,0,0,1) // Special sentinel code which cannot be used as a regular color.
2707-
#define IMGUI_TABLE_MAX_COLUMNS 512 // May be further lifted
2708-
2709-
// Our current column maximum is 64 but we may raise that in the future.
2710-
typedef ImS16 ImGuiTableColumnIdx;
2711-
typedef ImU16 ImGuiTableDrawChannelIdx;
2712+
#define IMGUI_TABLE_MAX_COLUMNS 512 // Arbitrary "safety" maximum, may be lifted in the future if needed. Must fit in ImGuiTableColumnIdx/ImGuiTableDrawChannelIdx.
27122713

27132714
// [Internal] sizeof() ~ 112
27142715
// We use the terminology "Enabled" to refer to a column that is not Hidden by user/api.
@@ -3344,6 +3345,8 @@ namespace ImGui
33443345
IMGUI_API float TableGetHeaderAngledMaxLabelWidth();
33453346
IMGUI_API void TablePushBackgroundChannel();
33463347
IMGUI_API void TablePopBackgroundChannel();
3348+
IMGUI_API void TablePushColumnChannel(int column_n);
3349+
IMGUI_API void TablePopColumnChannel();
33473350
IMGUI_API void TableAngledHeadersRowEx(ImGuiID row_id, float angle, float max_label_width, const ImGuiTableHeaderData* data, int data_count);
33483351

33493352
// 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
@@ -6562,7 +6562,9 @@ static void TreeNodeStoreStackData(ImGuiTreeNodeFlags flags, float x1)
65626562
tree_node_data->NavRect = g.LastItemData.NavRect;
65636563

65646564
// Initially I tried to latch value for GetColorU32(ImGuiCol_TreeLines) but it's not a good trade-off for very large trees.
6565-
tree_node_data->DrawLinesX1 = (flags & (ImGuiTreeNodeFlags_DrawLinesFull | ImGuiTreeNodeFlags_DrawLinesToNodes)) ? (x1 + g.FontSize * 0.5f + g.Style.FramePadding.x) : +FLT_MAX;
6565+
const bool draw_lines = (flags & (ImGuiTreeNodeFlags_DrawLinesFull | ImGuiTreeNodeFlags_DrawLinesToNodes)) != 0;
6566+
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;
65666568
tree_node_data->DrawLinesY2 = -FLT_MAX;
65676569
window->DC.TreeHasStackDataDepthMask |= (1 << window->DC.TreeDepth);
65686570
}
@@ -6919,7 +6921,11 @@ void ImGui::TreePop()
69196921
if (y1 < y2)
69206922
{
69216923
float x = ImTrunc(data->DrawLinesX1);
6924+
if (data->DrawLinesTableColumn != -1)
6925+
TablePushColumnChannel(data->DrawLinesTableColumn);
69226926
window->DrawList->AddLine(ImVec2(x, y1), ImVec2(x, y2), GetColorU32(ImGuiCol_TreeLines), g.Style.TreeLinesSize);
6927+
if (data->DrawLinesTableColumn != -1)
6928+
TablePopColumnChannel();
69236929
}
69246930
}
69256931
g.TreeNodeStack.pop_back();

0 commit comments

Comments
 (0)