@@ -369,7 +369,6 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
369
369
table->FreezeColumnsRequest = table->FreezeColumnsCount = 0 ;
370
370
table->IsUnfrozen = true ;
371
371
table->DeclColumnsCount = 0 ;
372
- table->RightMostEnabledColumn = -1 ;
373
372
374
373
// Using opaque colors facilitate overlapping elements of the grid
375
374
table->BorderColorStrong = GetColorU32 (ImGuiCol_TableBorderStrong);
@@ -709,7 +708,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
709
708
float sum_weights_stretched = 0 .0f ; // Sum of all weights for weighted columns.
710
709
float sum_width_fixed_requests = 0 .0f ; // Sum of all width for fixed and auto-resize columns, excluding width contributed by Stretch columns.
711
710
float max_width_auto = 0 .0f ; // Largest auto-width (used for SameWidths feature)
712
- table->LeftMostStretchedColumnDisplayOrder = -1 ;
711
+ table->LeftMostStretchedColumn = table-> RightMostStretchedColumn = -1 ;
713
712
for (int column_n = 0 ; column_n < table->ColumnsCount ; column_n++)
714
713
{
715
714
if (!(table->EnabledMaskByIndex & ((ImU64)1 << column_n)))
@@ -760,11 +759,16 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
760
759
else
761
760
{
762
761
IM_ASSERT (column->Flags & ImGuiTableColumnFlags_WidthStretch);
763
- if (column->StretchWeight < 0 .0f )
764
- column->StretchWeight = 1 .0f ;
762
+
763
+ // Revert or initialize weight (when column->StretchWeight < 0.0f normally it means there has been no init value so it'll always default to 1.0f)
764
+ if (column->AutoFitQueue != 0x00 || column->StretchWeight < 0 .0f )
765
+ column->StretchWeight = (column->InitStretchWeightOrWidth > 0 .0f ) ? column->InitStretchWeightOrWidth : 1 .0f ;
766
+
765
767
sum_weights_stretched += column->StretchWeight ;
766
- if (table->LeftMostStretchedColumnDisplayOrder == -1 || table->LeftMostStretchedColumnDisplayOrder > column->DisplayOrder )
767
- table->LeftMostStretchedColumnDisplayOrder = column->DisplayOrder ;
768
+ if (table->LeftMostStretchedColumn == -1 || table->Columns [table->LeftMostStretchedColumn ].DisplayOrder > column->DisplayOrder )
769
+ table->LeftMostStretchedColumn = (ImGuiTableColumnIdx)column_n;
770
+ if (table->RightMostStretchedColumn == -1 || table->Columns [table->RightMostStretchedColumn ].DisplayOrder < column->DisplayOrder )
771
+ table->RightMostStretchedColumn = (ImGuiTableColumnIdx)column_n;
768
772
}
769
773
max_width_auto = ImMax (max_width_auto, column->WidthAuto );
770
774
sum_width_fixed_requests += table->CellPaddingX * 2 .0f ;
@@ -831,8 +835,8 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
831
835
}
832
836
833
837
// [Resize Rule 1] The right-most Visible column is not resizable if there is at least one Stretch column
834
- // (see comments in TableResizeColumn())
835
- if (column->NextEnabledColumn == -1 && table->LeftMostStretchedColumnDisplayOrder != -1 )
838
+ // See additional comments in TableSetColumnWidth().
839
+ if (column->NextEnabledColumn == -1 && table->LeftMostStretchedColumn != -1 )
836
840
column->Flags |= ImGuiTableColumnFlags_NoDirectResize_;
837
841
838
842
// Assign final width, record width in case we will need to shrink
@@ -1885,7 +1889,7 @@ void ImGui::TableSetColumnWidth(int column_n, float width)
1885
1889
// [Resize Rule 3] If we are are followed by a fixed column and we have a Stretch column before, we need to ensure
1886
1890
// that our left border won't move, which we can do by making sure column_a/column_b resizes cancels each others.
1887
1891
if (column_1 && (column_1->Flags & ImGuiTableColumnFlags_WidthFixed))
1888
- if (table->LeftMostStretchedColumnDisplayOrder != -1 && table->LeftMostStretchedColumnDisplayOrder < column_0->DisplayOrder )
1892
+ if (table->LeftMostStretchedColumn != -1 && table->Columns [table-> LeftMostStretchedColumn ]. DisplayOrder < column_0->DisplayOrder )
1889
1893
{
1890
1894
// (old_a + old_b == new_a + new_b) --> (new_a == old_a + old_b - new_b)
1891
1895
float column_1_width = ImMax (column_1->WidthRequest - (column_0_width - column_0->WidthRequest ), min_width);
@@ -1933,9 +1937,10 @@ void ImGui::TableSetColumnWidthAutoSingle(ImGuiTable* table, int column_n)
1933
1937
if (!column->IsEnabled )
1934
1938
return ;
1935
1939
column->CannotSkipItemsQueue = (1 << 0 );
1936
- column->AutoFitQueue = (1 << 1 );
1937
1940
if (column->Flags & ImGuiTableColumnFlags_WidthStretch)
1938
1941
table->AutoFitSingleStretchColumn = (ImGuiTableColumnIdx)column_n;
1942
+ else
1943
+ column->AutoFitQueue = (1 << 1 );
1939
1944
}
1940
1945
1941
1946
void ImGui::TableSetColumnWidthAutoAll (ImGuiTable* table)
@@ -1952,7 +1957,7 @@ void ImGui::TableSetColumnWidthAutoAll(ImGuiTable* table)
1952
1957
1953
1958
void ImGui::TableUpdateColumnsWeightFromWidth (ImGuiTable* table)
1954
1959
{
1955
- IM_ASSERT (table->LeftMostStretchedColumnDisplayOrder != -1 );
1960
+ IM_ASSERT (table->LeftMostStretchedColumn != - 1 && table-> RightMostStretchedColumn != -1 );
1956
1961
1957
1962
// Measure existing quantity
1958
1963
float visible_weight = 0 .0f ;
@@ -2506,7 +2511,7 @@ void ImGui::TableSortSpecsSanitize(ImGuiTable* table)
2506
2511
{
2507
2512
sort_order_count = 1 ;
2508
2513
column->SortOrder = 0 ;
2509
- column->SortDirection = TableGetColumnAvailSortDirection (column, 0 );
2514
+ column->SortDirection = (ImU8) TableGetColumnAvailSortDirection (column, 0 );
2510
2515
break ;
2511
2516
}
2512
2517
}
@@ -2792,7 +2797,7 @@ void ImGui::TableDrawContextMenu(ImGuiTable* table)
2792
2797
if (column != NULL )
2793
2798
{
2794
2799
const bool can_resize = !(column->Flags & ImGuiTableColumnFlags_NoResize) && column->IsEnabled ;
2795
- if (MenuItem (" Size column to fit" , NULL , false , can_resize))
2800
+ if (MenuItem (" Size column to fit###SizeOne " , NULL , false , can_resize))
2796
2801
TableSetColumnWidthAutoSingle (table, column_n);
2797
2802
}
2798
2803
0 commit comments