@@ -271,7 +271,6 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
271
271
272
272
// Acquire storage for the table
273
273
ImGuiTable* table = g.Tables .GetOrAddByKey (id);
274
- const bool table_is_new = (table->ID == 0 );
275
274
const int instance_no = (table->LastFrameActive != g.FrameCount ) ? 0 : table->InstanceCurrent + 1 ;
276
275
const ImGuiID instance_id = id + instance_no;
277
276
const ImGuiTableFlags table_last_flags = table->Flags ;
@@ -288,7 +287,6 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
288
287
table->LastFrameActive = g.FrameCount ;
289
288
table->OuterWindow = table->InnerWindow = outer_window;
290
289
table->ColumnsCount = columns_count;
291
- table->IsInitializing = false ;
292
290
table->IsLayoutLocked = false ;
293
291
table->InnerWidth = inner_width;
294
292
table->OuterRect = outer_rect;
@@ -415,10 +413,25 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
415
413
if (table->RawData == NULL )
416
414
{
417
415
TableBeginInitMemory (table, columns_count);
418
- if (table_is_new)
419
- table->IsInitializing = true ;
420
- table->IsSortSpecsDirty = table->IsSettingsRequestLoad = true ;
416
+ table->IsInitializing = table->IsSettingsRequestLoad = true ;
417
+ }
418
+ if (table->IsResetAllRequest )
419
+ TableResetSettings (table);
420
+ if (table->IsInitializing )
421
+ {
422
+ // Initialize for new settings
421
423
table->SettingsOffset = -1 ;
424
+ table->IsSortSpecsDirty = true ;
425
+ for (int n = 0 ; n < columns_count; n++)
426
+ {
427
+ ImGuiTableColumn* column = &table->Columns [n];
428
+ float width_auto = column->WidthAuto ;
429
+ *column = ImGuiTableColumn ();
430
+ column->WidthAuto = width_auto;
431
+ column->IsPreserveWidthAuto = true ; // Preserve WidthAuto when reinitializing a live table: not technically necessary but remove a visible flicker
432
+ column->DisplayOrder = table->DisplayOrderToIndex [n] = (ImGuiTableColumnIdx)n;
433
+ column->IsEnabled = column->IsEnabledNextFrame = true ;
434
+ }
422
435
}
423
436
424
437
// Load settings
@@ -479,19 +492,11 @@ void ImGui::TableBeginInitMemory(ImGuiTable* table, int columns_count)
479
492
span_allocator.ReserveBytes (1 , columns_count * sizeof (ImGuiTableColumnIdx));
480
493
span_allocator.ReserveBytes (2 , columns_count * sizeof (ImGuiTableCellData));
481
494
table->RawData = IM_ALLOC (span_allocator.GetArenaSizeInBytes ());
495
+ memset (table->RawData , 0 , span_allocator.GetArenaSizeInBytes ());
482
496
span_allocator.SetArenaBasePtr (table->RawData );
483
497
span_allocator.GetSpan (0 , &table->Columns );
484
498
span_allocator.GetSpan (1 , &table->DisplayOrderToIndex );
485
499
span_allocator.GetSpan (2 , &table->RowCellData );
486
-
487
- memset (table->RowCellData .Data , 0 , table->RowCellData .size_in_bytes ());
488
- for (int n = 0 ; n < columns_count; n++)
489
- {
490
- ImGuiTableColumn* column = &table->Columns [n];
491
- *column = ImGuiTableColumn ();
492
- column->DisplayOrder = table->DisplayOrderToIndex [n] = (ImGuiTableColumnIdx)n;
493
- column->AutoFitQueue = column->CannotSkipItemsQueue = (1 << 3 ) - 1 ; // Fit for three frames
494
- }
495
500
}
496
501
497
502
// Apply queued resizing/reordering/hiding requests
@@ -513,7 +518,6 @@ void ImGui::TableBeginApplyRequests(ImGuiTable* table)
513
518
// FIXME-TABLE: Would be nice to redistribute available stretch space accordingly to other weights, instead of giving it all to siblings.
514
519
if (table->AutoFitSingleStretchColumn != -1 )
515
520
{
516
- table->Columns [table->AutoFitSingleStretchColumn ].AutoFitQueue = 0x00 ;
517
521
TableSetColumnWidth (table->AutoFitSingleStretchColumn , table->Columns [table->AutoFitSingleStretchColumn ].WidthAuto );
518
522
table->AutoFitSingleStretchColumn = -1 ;
519
523
}
@@ -635,6 +639,15 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
635
639
}
636
640
if (column->SortOrder > 0 && !(table->Flags & ImGuiTableFlags_MultiSortable))
637
641
table->IsSortSpecsDirty = true ;
642
+
643
+ bool start_auto_fit = false ;
644
+ if (column->Flags & (ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_WidthAutoResize))
645
+ start_auto_fit = column->WidthRequest < 0 .0f ;
646
+ else
647
+ start_auto_fit = column->StretchWeight < 0 .0f ;
648
+ if (start_auto_fit)
649
+ column->AutoFitQueue = column->CannotSkipItemsQueue = (1 << 3 ) - 1 ; // Fit for three frames
650
+
638
651
if (column->AutoFitQueue != 0x00 )
639
652
want_column_auto_fit = true ;
640
653
@@ -698,6 +711,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
698
711
699
712
// Calculate ideal/auto column width (that's the width required for all contents to be visible without clipping)
700
713
// Combine width from regular rows + width from headers unless requested not to.
714
+ if (!column->IsPreserveWidthAuto )
701
715
{
702
716
const float content_width_body = (float )ImMax (column->ContentMaxXFrozen , column->ContentMaxXUnfrozen ) - column->WorkMinX ;
703
717
const float content_width_headers = (float )column->ContentMaxXHeadersIdeal - column->WorkMinX ;
@@ -708,11 +722,12 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
708
722
709
723
// Non-resizable columns also submit their requested width
710
724
if ((column->Flags & ImGuiTableColumnFlags_WidthFixed) && column->InitStretchWeightOrWidth > 0 .0f )
711
- if (!(table->Flags & ImGuiTableFlags_Resizable) || ! (column->Flags & ImGuiTableColumnFlags_NoResize))
725
+ if (!(table->Flags & ImGuiTableFlags_Resizable) || (column->Flags & ImGuiTableColumnFlags_NoResize))
712
726
width_auto = ImMax (width_auto, column->InitStretchWeightOrWidth );
713
727
714
728
column->WidthAuto = width_auto;
715
729
}
730
+ column->IsPreserveWidthAuto = false ;
716
731
717
732
if (column->Flags & (ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_WidthAutoResize))
718
733
{
@@ -734,9 +749,8 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
734
749
else
735
750
{
736
751
IM_ASSERT (column->Flags & ImGuiTableColumnFlags_WidthStretch);
737
- const float default_weight = (column->InitStretchWeightOrWidth > 0 .0f ) ? column->InitStretchWeightOrWidth : 1 .0f ;
738
- if (column->AutoFitQueue != 0x00 )
739
- column->StretchWeight = default_weight;
752
+ if (column->StretchWeight < 0 .0f )
753
+ column->StretchWeight = 1 .0f ;
740
754
sum_weights_stretched += column->StretchWeight ;
741
755
if (table->LeftMostStretchedColumnDisplayOrder == -1 || table->LeftMostStretchedColumnDisplayOrder > column->DisplayOrder )
742
756
table->LeftMostStretchedColumnDisplayOrder = column->DisplayOrder ;
@@ -1232,6 +1246,7 @@ void ImGui::EndTable()
1232
1246
// Save settings
1233
1247
if (table->IsSettingsDirty )
1234
1248
TableSaveSettings (table);
1249
+ table->IsInitializing = false ;
1235
1250
1236
1251
// Clear or restore current table, if any
1237
1252
IM_ASSERT (g.CurrentWindow == outer_window && g.CurrentTable == table);
@@ -2731,6 +2746,10 @@ void ImGui::TableDrawContextMenu(ImGuiTable* table)
2731
2746
want_separator = true ;
2732
2747
}
2733
2748
2749
+ // Reset all (should work but seems unnecessary/noisy to expose?)
2750
+ // if (MenuItem("Reset all"))
2751
+ // table->IsResetAllRequest = true;
2752
+
2734
2753
// Sorting
2735
2754
// (modify TableOpenContextMenu() to add _Sortable flag if enabling this)
2736
2755
#if 0
@@ -2777,12 +2796,14 @@ void ImGui::TableDrawContextMenu(ImGuiTable* table)
2777
2796
// -------------------------------------------------------------------------
2778
2797
// [SECTION] Tables: Settings (.ini data)
2779
2798
// -------------------------------------------------------------------------
2799
+ // FIXME: The binding/finding/creating flow are too confusing.
2800
+ // -------------------------------------------------------------------------
2780
2801
// - TableSettingsInit() [Internal]
2781
2802
// - TableSettingsCalcChunkSize() [Internal]
2782
2803
// - TableSettingsCreate() [Internal]
2783
2804
// - TableSettingsFindByID() [Internal]
2784
- // - TableSettingsClearByID() [Internal]
2785
2805
// - TableGetBoundSettings() [Internal]
2806
+ // - TableResetSettings()
2786
2807
// - TableSaveSettings() [Internal]
2787
2808
// - TableLoadSettings() [Internal]
2788
2809
// - TableSettingsHandler_ClearAll() [Internal]
@@ -2835,12 +2856,6 @@ ImGuiTableSettings* ImGui::TableSettingsFindByID(ImGuiID id)
2835
2856
return NULL ;
2836
2857
}
2837
2858
2838
- void ImGui::TableSettingsClearByID (ImGuiID id)
2839
- {
2840
- if (ImGuiTableSettings* settings = TableSettingsFindByID (id))
2841
- settings->ID = 0 ;
2842
- }
2843
-
2844
2859
// Get settings for a given table, NULL if none
2845
2860
ImGuiTableSettings* ImGui::TableGetBoundSettings (ImGuiTable* table)
2846
2861
{
@@ -2856,6 +2871,15 @@ ImGuiTableSettings* ImGui::TableGetBoundSettings(ImGuiTable* table)
2856
2871
return NULL ;
2857
2872
}
2858
2873
2874
+ // Restore initial state of table (with or without saved settings)
2875
+ void ImGui::TableResetSettings (ImGuiTable* table)
2876
+ {
2877
+ table->IsInitializing = table->IsSettingsDirty = true ;
2878
+ table->IsResetAllRequest = false ;
2879
+ table->IsSettingsRequestLoad = false ; // Don't reload from ini
2880
+ table->SettingsLoadedFlags = ImGuiTableFlags_None; // Mark as nothing loaded so our initialized data becomes authoritative
2881
+ }
2882
+
2859
2883
void ImGui::TableSaveSettings (ImGuiTable* table)
2860
2884
{
2861
2885
table->IsSettingsDirty = false ;
@@ -3163,6 +3187,7 @@ void ImGui::DebugNodeTable(ImGuiTable* table)
3163
3187
GetForegroundDrawList ()->AddRect (table->OuterRect .Min , table->OuterRect .Max , IM_COL32 (255 , 255 , 0 , 255 ));
3164
3188
if (!open)
3165
3189
return ;
3190
+ bool clear_settings = SmallButton (" Clear settings" );
3166
3191
BulletText (" OuterRect: Pos: (%.1f,%.1f) Size: (%.1f,%.1f)" , table->OuterRect .Min .x , table->OuterRect .Min .y , table->OuterRect .GetWidth (), table->OuterRect .GetHeight ());
3167
3192
BulletText (" ColumnsWidth: %.1f, AutoFitWidth: %.1f, InnerWidth: %.1f%s" , table->ColumnsTotalWidth , table->ColumnsAutoFitWidth , table->InnerWidth , table->InnerWidth == 0 .0f ? " (auto)" : " " );
3168
3193
BulletText (" CellPaddingX: %.1f, CellSpacingX: %.1f/%.1f, OuterPaddingX: %.1f" , table->CellPaddingX , table->CellSpacingX1 , table->CellSpacingX2 , table->OuterPaddingX );
@@ -3200,6 +3225,8 @@ void ImGui::DebugNodeTable(ImGuiTable* table)
3200
3225
}
3201
3226
if (ImGuiTableSettings* settings = TableGetBoundSettings (table))
3202
3227
DebugNodeTableSettings (settings);
3228
+ if (clear_settings)
3229
+ table->IsResetAllRequest = true ;
3203
3230
TreePop ();
3204
3231
}
3205
3232
@@ -3221,7 +3248,12 @@ void ImGui::DebugNodeTableSettings(ImGuiTableSettings* settings)
3221
3248
TreePop ();
3222
3249
}
3223
3250
3224
- #endif // #ifndef IMGUI_DISABLE_METRICS_WINDOW
3251
+ #else // #ifndef IMGUI_DISABLE_METRICS_WINDOW
3252
+
3253
+ void ImGui::DebugNodeTable (ImGuiTable*) {}
3254
+ void ImGui::DebugNodeTableSettings (ImGuiTableSettings*) {}
3255
+
3256
+ #endif
3225
3257
3226
3258
3227
3259
// -------------------------------------------------------------------------
0 commit comments