69
69
// | - TableUpdateColumnsWeightFromWidth()- recompute columns weights (of stretch columns) from their respective width
70
70
// - TableSetupColumn() user submit columns details (optional)
71
71
// - TableSetupScrollFreeze() user submit scroll freeze information (optional)
72
- // - TableUpdateLayout() [Internal] automatically called by the FIRST call to TableNextRow() or Table*Header (): lock all widths, columns positions, clipping rectangles
72
+ // - TableUpdateLayout() [Internal] automatically called by the FIRST call to TableNextRow() or TableHeadersRow (): lock all widths, columns positions, clipping rectangles
73
73
// | TableUpdateDrawChannels() - setup ImDrawList channels
74
74
// | TableUpdateBorders() - detect hovering columns for resize, ahead of contents submission
75
75
// | TableDrawContextMenu() - draw right-click context menu
78
78
// | TableSortSpecsClickColumn() - when left-clicked: alter sort order and sort direction
79
79
// | TableOpenContextMenu() - when right-clicked: trigger opening of the default context menu
80
80
// - TableGetSortSpecs() user queries updated sort specs (optional, generally after submitting headers)
81
- // - TableNextRow() / TableNextColumn() user begin into the first row, also automatically called by TableHeadersRow()
82
- // | TableEndCell() - close existing cell if not the first time
81
+ // - TableNextRow() user begin into a new row (also automatically called by TableHeadersRow())
82
+ // | TableEndRow() - finish existing row
83
+ // | TableBeginRow() - add a new row
84
+ // - TableSetColumnIndex() / TableNextColumn() user begin into a cell
85
+ // | TableEndCell() - close existing cell
83
86
// | TableBeginCell() - enter into current cell
84
87
// - [...] user emit contents
85
88
// -----------------------------------------------------------------------------
@@ -430,7 +433,7 @@ void ImGui::TableBeginUpdateColumns(ImGuiTable* table)
430
433
if (table->InstanceCurrent == 0 )
431
434
{
432
435
if (table->ResizedColumn != -1 && table->ResizedColumnNextWidth != FLT_MAX)
433
- TableSetColumnWidth (table, &table-> Columns [table-> ResizedColumn ] , table->ResizedColumnNextWidth );
436
+ TableSetColumnWidth (table-> ResizedColumn , table->ResizedColumnNextWidth );
434
437
table->LastResizedColumn = table->ResizedColumn ;
435
438
table->ResizedColumnNextWidth = FLT_MAX;
436
439
table->ResizedColumn = -1 ;
@@ -1215,21 +1218,16 @@ static void TableUpdateColumnsWeightFromWidth(ImGuiTable* table)
1215
1218
}
1216
1219
}
1217
1220
1218
- // Public wrapper
1219
1221
// 'width' = inner column width, without padding
1220
1222
void ImGui::TableSetColumnWidth (int column_n, float width)
1221
1223
{
1222
1224
ImGuiContext& g = *GImGui;
1223
1225
ImGuiTable* table = g.CurrentTable ;
1224
- IM_ASSERT (table != NULL );
1225
- IM_ASSERT (table->IsLayoutLocked == false );
1226
+ IM_ASSERT (table != NULL && table->IsLayoutLocked == false );
1226
1227
IM_ASSERT (column_n >= 0 && column_n < table->ColumnsCount );
1227
- TableSetColumnWidth (table, &table->Columns [column_n], width) ;
1228
- }
1228
+ ImGuiTableColumn* column_0 = &table->Columns [column_n];
1229
+ float column_0_width = width;
1229
1230
1230
- // [Internal]
1231
- void ImGui::TableSetColumnWidth (ImGuiTable* table, ImGuiTableColumn* column_0, float column_0_width)
1232
- {
1233
1231
// Constraints
1234
1232
const float min_width = TableGetMinColumnWidth ();
1235
1233
float max_width_0 = FLT_MAX;
@@ -1303,6 +1301,16 @@ void ImGui::TableSetColumnWidth(ImGuiTable* table, ImGuiTableColumn* column_0, f
1303
1301
}
1304
1302
}
1305
1303
1304
+ // Public wrapper
1305
+ void ImGui::TableSetColumnVisible (int column_n, bool visible)
1306
+ {
1307
+ ImGuiContext& g = *GImGui;
1308
+ ImGuiTable* table = g.CurrentTable ;
1309
+ IM_ASSERT (table != NULL && table->IsLayoutLocked == false );
1310
+ IM_ASSERT (column_n >= 0 && column_n < table->ColumnsCount );
1311
+ table->Columns [column_n].IsVisibleNextFrame = visible;
1312
+ }
1313
+
1306
1314
// Allocate draw channels. Called by TableUpdateLayout()
1307
1315
// - We allocate them following storage order instead of display order so reordering columns won't needlessly
1308
1316
// increase overall dormant memory cost.
@@ -1314,10 +1322,11 @@ void ImGui::TableSetColumnWidth(ImGuiTable* table, ImGuiTableColumn* column_0, f
1314
1322
// - We allocate 1 or 2 background draw channels. This is because we know PushTableBackground() is only used for
1315
1323
// horizontal spanning. If we allowed vertical spanning we'd need one background draw channel per merge group (1-4).
1316
1324
// Draw channel allocation (before merging):
1317
- // - NoClip --> 1+1 channels: background + foreground (same clip rect == 1 draw call)
1318
- // - Clip --> 1+N channels
1319
- // - FreezeRows --> 1+N*2 (unless scrolling value is zero)
1320
- // - FreezeRows || FreezeColunns --> 2+N*2 (unless scrolling value is zero)
1325
+ // - NoClip --> 1+D+1 channels: background + foreground (same clip rect == 1 draw call)
1326
+ // - Clip --> 1+D+N channels
1327
+ // - FreezeRows --> 1+D+N*2 (unless scrolling value is zero)
1328
+ // - FreezeRows || FreezeColunns --> 2+D+N*2 (unless scrolling value is zero)
1329
+ // Where D is 1 if any column is clipped or hidden (dummy channel) otherwise 0.
1321
1330
void ImGui::TableUpdateDrawChannels (ImGuiTable* table)
1322
1331
{
1323
1332
const int freeze_row_multiplier = (table->FreezeRowsCount > 0 ) ? 2 : 1 ;
@@ -1466,12 +1475,13 @@ void ImGui::TableReorderDrawChannelsForMerge(ImGuiTable* table)
1466
1475
// 2. Rewrite channel list in our preferred order
1467
1476
if (merge_group_mask != 0 )
1468
1477
{
1469
- // Use shared temporary storage so the allocation gets amortized
1470
- g.DrawChannelsTempMergeBuffer .resize (splitter->_Count - 1 );
1478
+ // We skip background channel 0 from the shuffling since it won't move (see channels allocation in TableUpdateDrawChannels()).
1479
+ const int LEADING_DRAW_CHANNELS = 1 ;
1480
+ g.DrawChannelsTempMergeBuffer .resize (splitter->_Count - LEADING_DRAW_CHANNELS); // Use shared temporary storage so the allocation gets amortized
1471
1481
ImDrawChannel* dst_tmp = g.DrawChannelsTempMergeBuffer .Data ;
1472
- ImBitArray<IMGUI_TABLE_MAX_DRAW_CHANNELS> remaining_mask; // We need 130 -bit of storage
1482
+ ImBitArray<IMGUI_TABLE_MAX_DRAW_CHANNELS> remaining_mask; // We need 131 -bit of storage
1473
1483
remaining_mask.ClearBits ();
1474
- remaining_mask.SetBitRange (1 , splitter->_Count - 1 ); // Background channel 0 == table->BgDrawChannlFrozen, not part of the merge (see channel allocation in TableUpdateDrawChannels)
1484
+ remaining_mask.SetBitRange (LEADING_DRAW_CHANNELS , splitter->_Count - 1 );
1475
1485
remaining_mask.ClearBit (table->BgDrawChannelUnfrozen );
1476
1486
int remaining_count = splitter->_Count - ((table->BgDrawChannelUnfrozen == 0 ) ? 1 : 2 );
1477
1487
// ImRect host_rect = (table->InnerWindow == table->OuterWindow) ? table->InnerClipRect : table->HostClipRect;
@@ -1536,7 +1546,7 @@ void ImGui::TableReorderDrawChannelsForMerge(ImGuiTable* table)
1536
1546
remaining_count--;
1537
1547
}
1538
1548
IM_ASSERT (dst_tmp == g.DrawChannelsTempMergeBuffer .Data + g.DrawChannelsTempMergeBuffer .Size );
1539
- memcpy (splitter->_Channels .Data + 1 , g.DrawChannelsTempMergeBuffer .Data , (splitter->_Count - 1 ) * sizeof (ImDrawChannel));
1549
+ memcpy (splitter->_Channels .Data + LEADING_DRAW_CHANNELS , g.DrawChannelsTempMergeBuffer .Data , (splitter->_Count - LEADING_DRAW_CHANNELS ) * sizeof (ImDrawChannel));
1540
1550
}
1541
1551
}
1542
1552
@@ -1726,10 +1736,9 @@ void ImGui::TableEndRow(ImGuiTable* table)
1726
1736
// Decide of top border color
1727
1737
ImU32 border_col = 0 ;
1728
1738
const float border_size = TABLE_BORDER_SIZE;
1729
- if (table->CurrentRow != 0 || table->InnerWindow == table->OuterWindow )
1739
+ if (table->CurrentRow > 0 || table->InnerWindow == table->OuterWindow )
1730
1740
if (table->Flags & ImGuiTableFlags_BordersInnerH)
1731
- if (table->CurrentRow > 0 )
1732
- border_col = (table->LastRowFlags & ImGuiTableRowFlags_Headers) ? table->BorderColorStrong : table->BorderColorLight ;
1741
+ border_col = (table->LastRowFlags & ImGuiTableRowFlags_Headers) ? table->BorderColorStrong : table->BorderColorLight ;
1733
1742
1734
1743
const bool draw_cell_bg_color = table->RowCellDataCurrent >= 0 ;
1735
1744
const bool draw_strong_bottom_border = unfreeze_rows_actual;
@@ -1791,7 +1800,6 @@ void ImGui::TableEndRow(ImGuiTable* table)
1791
1800
{
1792
1801
IM_ASSERT (table->IsUnfrozen == false );
1793
1802
table->IsUnfrozen = true ;
1794
- table->DrawSplitter .SetCurrentChannel (window->DrawList , table->BgDrawChannelUnfrozen );
1795
1803
1796
1804
// BgClipRect starts as table->InnerClipRect, reduce it now and make BgClipRectForDrawCmd == BgClipRect
1797
1805
float y0 = ImMax (table->RowPosY2 + 1 , window->InnerClipRect .Min .y );
@@ -2322,7 +2330,7 @@ void ImGui::TableHeader(const char* label)
2322
2330
sort_direction = (column->Flags & ImGuiTableColumnFlags_PreferSortDescending) ? ImGuiSortDirection_Descending : ImGuiSortDirection_Ascending;
2323
2331
else
2324
2332
sort_direction = (column->SortDirection == ImGuiSortDirection_Ascending) ? ImGuiSortDirection_Descending : ImGuiSortDirection_Ascending;
2325
- TableSetColumnSortDirection (table, column_n, sort_direction, g.IO .KeyShift );
2333
+ TableSetColumnSortDirection (column_n, sort_direction, g.IO .KeyShift );
2326
2334
}
2327
2335
}
2328
2336
@@ -2347,8 +2355,11 @@ void ImGui::TableHeader(const char* label)
2347
2355
2348
2356
// Note that the NoSortAscending/NoSortDescending flags are processed in TableSortSpecsSanitize(), and they may change/revert
2349
2357
// the value of SortDirection. We could technically also do it here but it would be unnecessary and duplicate code.
2350
- void ImGui::TableSetColumnSortDirection (ImGuiTable* table, int column_n, ImGuiSortDirection sort_direction, bool append_to_sort_specs)
2358
+ void ImGui::TableSetColumnSortDirection (int column_n, ImGuiSortDirection sort_direction, bool append_to_sort_specs)
2351
2359
{
2360
+ ImGuiContext& g = *GImGui;
2361
+ ImGuiTable* table = g.CurrentTable ;
2362
+
2352
2363
if (!(table->Flags & ImGuiTableFlags_MultiSortable))
2353
2364
append_to_sort_specs = false ;
2354
2365
0 commit comments