@@ -610,7 +610,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
610
610
// (can't make auto padding larger than what WorkRect knows about so right-alignment matches)
611
611
const ImRect work_rect = table->WorkRect ;
612
612
const float min_column_width = TableGetMinColumnWidth ();
613
- const float min_column_width_padded = min_column_width + table->CellPaddingX * 2 .0f ;
613
+ const float min_column_distance = min_column_width + table->CellPaddingX * 2 .0f ;
614
614
615
615
int count_fixed = 0 ;
616
616
float sum_weights_stretched = 0 .0f ; // Sum of all weights for weighted columns.
@@ -641,7 +641,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
641
641
float width_auto = content_width_body;
642
642
if (!(table->Flags & ImGuiTableFlags_NoHeadersWidth) && !(column->Flags & ImGuiTableColumnFlags_NoHeaderWidth))
643
643
width_auto = ImMax (width_auto, content_width_headers);
644
- width_auto = ImMax (width_auto, min_column_width); // Without padding
644
+ width_auto = ImMax (width_auto, min_column_width);
645
645
646
646
// Non-resizable columns also submit their requested width
647
647
if ((column->Flags & ImGuiTableColumnFlags_WidthFixed) && column->InitStretchWeightOrWidth > 0 .0f )
@@ -731,31 +731,6 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
731
731
table->ColumnsAutoFitWidth += column->WidthAuto + table->CellPaddingX * 2 .0f ;
732
732
}
733
733
734
- #if 0
735
- const float width_excess = table->ColumnsTotalWidth - work_rect.GetWidth();
736
- if ((table->Flags & ImGuiTableFlags_SizingPolicyStretchX) && width_excess > 0.0f)
737
- {
738
- // Shrink widths when the total does not fit
739
- // FIXME-TABLE: This is working but confuses/conflicts with manual resizing.
740
- // FIXME-TABLE: Policy to shrink down below below ideal/requested width if there's no room?
741
- g.ShrinkWidthBuffer.resize(table->ColumnsVisibleCount);
742
- for (int order_n = 0, visible_n = 0; order_n < table->ColumnsCount; order_n++)
743
- {
744
- if (!(table->VisibleMaskByDisplayOrder & ((ImU64)1 << order_n)))
745
- continue;
746
- const int column_n = table->DisplayOrder[order_n];
747
- g.ShrinkWidthBuffer[visible_n].Index = column_n;
748
- g.ShrinkWidthBuffer[visible_n].Width = table->Columns[column_n].WidthGiven;
749
- visible_n++;
750
- }
751
- ShrinkWidths(g.ShrinkWidthBuffer.Data, g.ShrinkWidthBuffer.Size, width_excess);
752
- for (int n = 0; n < g.ShrinkWidthBuffer.Size; n++)
753
- table->Columns[g.ShrinkWidthBuffer.Data[n].Index].WidthGiven = ImMax(g.ShrinkWidthBuffer.Data[n].Width, min_column_size);
754
- // FIXME: Need to alter table->ColumnsTotalWidth
755
- }
756
- else
757
- #endif
758
-
759
734
// Redistribute remainder width due to rounding (remainder width is < 1.0f * number of Stretch column).
760
735
// Using right-to-left distribution (more likely to match resizing cursor), could be adjusted depending
761
736
// on where the mouse cursor is and/or relative weights.
@@ -780,6 +755,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
780
755
int visible_n = 0 ;
781
756
float offset_x = (table->FreezeColumnsCount > 0 ) ? table->OuterRect .Min .x : work_rect.Min .x ;
782
757
offset_x += table->OuterPaddingX ;
758
+ offset_x -= table->CellSpacingX1 ;
783
759
ImRect host_clip_rect = table->InnerClipRect ;
784
760
for (int order_n = 0 ; order_n < table->ColumnsCount ; order_n++)
785
761
{
@@ -795,11 +771,9 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
795
771
{
796
772
// Hidden column: clear a few fields and we are done with it for the remainder of the function.
797
773
// We set a zero-width clip rect but set Min.y/Max.y properly to not interfere with the clipper.
798
- column->MinX = column->MaxX = column->WorkMinX = offset_x;
774
+ column->MinX = column->MaxX = column->WorkMinX = column-> ClipRect . Min . x = column-> ClipRect . Max . x = offset_x;
799
775
column->WidthGiven = 0 .0f ;
800
- column->ClipRect .Min .x = offset_x;
801
776
column->ClipRect .Min .y = work_rect.Min .y ;
802
- column->ClipRect .Max .x = offset_x;
803
777
column->ClipRect .Max .y = FLT_MAX;
804
778
column->ClipRect .ClipWithFull (host_clip_rect);
805
779
column->IsClipped = column->IsSkipItems = true ;
@@ -811,23 +785,23 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
811
785
{
812
786
// Frozen columns can't reach beyond visible width else scrolling will naturally break.
813
787
if (order_n < table->FreezeColumnsRequest )
814
- max_x = table->InnerClipRect .Max .x - (table->FreezeColumnsRequest - order_n) * min_column_width_padded - table->OuterPaddingX ;
788
+ max_x = table->InnerClipRect .Max .x - (table->FreezeColumnsRequest - order_n) * min_column_distance - table->OuterPaddingX ;
815
789
}
816
790
else if ((table->Flags & ImGuiTableFlags_NoKeepColumnsVisible) == 0 )
817
791
{
818
792
// If horizontal scrolling if disabled, we apply a final lossless shrinking of columns in order to make
819
793
// sure they are all visible. Because of this we also know that all of the columns will always fit in
820
794
// table->WorkRect and therefore in table->InnerRect (because ScrollX is off)
821
- max_x = table->WorkRect .Max .x - (table->ColumnsVisibleCount - (column->IndexWithinVisibleSet + 1 )) * min_column_width_padded - table->OuterPaddingX ;
795
+ max_x = table->WorkRect .Max .x - (table->ColumnsVisibleCount - (column->IndexWithinVisibleSet + 1 )) * min_column_distance - table->OuterPaddingX ;
822
796
}
823
- if (offset_x + column->WidthGiven + table->CellPaddingX * 2 .0f > max_x)
824
- column->WidthGiven = ImMax (max_x - offset_x - table->CellPaddingX * 2 .0f , min_column_width);
825
-
826
- // Min, Max + starting positions
827
- column->MinX = offset_x - table-> CellSpacingX1 ;
828
- column->MaxX = offset_x + column->WidthGiven + table->CellSpacingX2 + table->CellPaddingX * 2 .0f ;
829
- column->WorkMinX = offset_x + table->CellPaddingX ;
830
-
797
+ if (offset_x + column->WidthGiven + table->CellPaddingX * 2 .0f + table-> CellSpacingX1 > max_x)
798
+ column->WidthGiven = ImMax (max_x - offset_x - table->CellPaddingX * 2 .0f - table-> CellSpacingX1 , min_column_width);
799
+
800
+ // Lock all our positions
801
+ column->MinX = offset_x;
802
+ column->MaxX = offset_x + column->WidthGiven + table->CellSpacingX1 + table-> CellSpacingX2 + table->CellPaddingX * 2 .0f ;
803
+ column->WorkMinX = column-> MinX + table->CellPaddingX + table-> CellSpacingX1 ;
804
+ column-> WorkMaxX = column-> MaxX - table-> CellPaddingX - table-> CellSpacingX2 ; // Expected max
831
805
column->ClipRect .Min .x = column->MinX ;
832
806
column->ClipRect .Min .y = work_rect.Min .y ;
833
807
column->ClipRect .Max .x = column->MaxX ;
@@ -844,24 +818,6 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
844
818
if (is_hovering_table && g.IO .MousePos .x >= column->ClipRect .Min .x && g.IO .MousePos .x < column->ClipRect .Max .x )
845
819
table->HoveredColumnBody = (ImS8)column_n;
846
820
847
- // [DEBUG] Display overlay
848
- #if 0
849
- if (g.IO.KeyShift)
850
- {
851
- // Note that ClipRect should always cover MinX..MaxX (in order to guarantee that draw calls can be merged into parent)
852
- float y1 = table->WorkRect.Min.y;
853
- float y2 = table->WorkRect.Min.y + table->LastOuterHeight;
854
- //GetForegroundDrawList()->AddLine(ImVec2(column->MinX, y1 - 5.0f), ImVec2(column->MinX, y2 + 5.0f), IM_COL32(0, 255, 50, 255));
855
- //GetForegroundDrawList()->AddLine(ImVec2(column->MaxX, y1 - 5.0f), ImVec2(column->MaxX, y2 + 5.0f), IM_COL32(0, 255, 50, 255));
856
- //GetForegroundDrawList()->AddRect(ImVec2(column->ClipRect.Min.x, y1), ImVec2(column->ClipRect.Max.x, y2), IM_COL32(255, 0, 0, 255), 0.0f, 0, 1.0f);
857
- //GetForegroundDrawList()->AddRect(ImVec2(column->MinX + table->CellPaddingX, y1), ImVec2(column->MaxX - table->CellPaddingX, y2), IM_COL32(255, 255, 0, 255));
858
- char buf[128];
859
- ImFormatString(buf, IM_ARRAYSIZE(buf), "(cont_w)\n%.2f\n(max-min)\n%.2f", column->MaxX - table->CellPaddingX - column->StartX, column->MaxX - column->MinX);
860
- GetForegroundDrawList()->AddRectFilled(ImVec2(column->MinX, y1), ImVec2(column->MaxX, y2), IM_COL32(0, 0, 0, 200));
861
- GetForegroundDrawList()->AddText(ImVec2(column->StartX, y1), IM_COL32(255, 255, 255, 255), buf);
862
- }
863
- #endif
864
-
865
821
// Alignment
866
822
// FIXME-TABLE: This align based on the whole column width, not per-cell, and therefore isn't useful in
867
823
// many cases (to be able to honor this we might be able to store a log of cells width, per row, for
@@ -1078,12 +1034,12 @@ void ImGui::EndTable()
1078
1034
else if (table->LastResizedColumn != -1 && table->ResizedColumn == -1 && inner_window->ScrollbarX && table->InstanceInteracted == table->InstanceCurrent )
1079
1035
{
1080
1036
// When releasing a column being resized, scroll to keep the resulting column in sight
1081
- const float min_column_width_padded = TableGetMinColumnWidth () + table->CellPaddingX * 2 .0f ;
1037
+ const float neighbor_width_to_keep_visible = TableGetMinColumnWidth () + table->CellPaddingX * 2 .0f ;
1082
1038
ImGuiTableColumn* column = &table->Columns [table->LastResizedColumn ];
1083
1039
if (column->MaxX < table->InnerClipRect .Min .x )
1084
- SetScrollFromPosX (inner_window, column->MaxX - inner_window->Pos .x - min_column_width_padded , 1 .0f );
1040
+ SetScrollFromPosX (inner_window, column->MaxX - inner_window->Pos .x - neighbor_width_to_keep_visible , 1 .0f );
1085
1041
else if (column->MaxX > table->InnerClipRect .Max .x )
1086
- SetScrollFromPosX (inner_window, column->MaxX - inner_window->Pos .x + min_column_width_padded , 1 .0f );
1042
+ SetScrollFromPosX (inner_window, column->MaxX - inner_window->Pos .x + neighbor_width_to_keep_visible , 1 .0f );
1087
1043
}
1088
1044
1089
1045
// Apply resizing/dragging at the end of the frame
@@ -1469,8 +1425,7 @@ void ImGui::TableReorderDrawChannelsForMerge(ImGuiTable* table)
1469
1425
content_max_x = ImMax (column->ContentMaxXFrozen , column->ContentMaxXHeadersUsed ); // Row freeze: use width before freeze
1470
1426
else
1471
1427
content_max_x = column->ContentMaxXUnfrozen ; // Row freeze: use width after freeze
1472
- float content_width = content_max_x - column->WorkMinX ;
1473
- if (content_width > column->WidthGiven + table->CellPaddingX * 1 .0f )
1428
+ if (content_max_x > column->ClipRect .Max .x )
1474
1429
continue ;
1475
1430
}
1476
1431
@@ -1805,10 +1760,11 @@ void ImGui::TableEndRow(ImGuiTable* table)
1805
1760
ImGuiTableCellData* cell_data_end = &table->RowCellData [table->RowCellDataCurrent ];
1806
1761
for (ImGuiTableCellData* cell_data = &table->RowCellData [0 ]; cell_data <= cell_data_end; cell_data++)
1807
1762
{
1763
+ const ImGuiTableColumn* column = &table->Columns [cell_data->Column ];
1808
1764
ImRect cell_bg_rect = TableGetCellBgRect (table, cell_data->Column );
1809
1765
cell_bg_rect.ClipWith (table->BgClipRect );
1810
- cell_bg_rect.Min .x = ImMax (cell_bg_rect.Min .x , table-> Columns [cell_data-> Column ]. ClipRect .Min .x );
1811
- cell_bg_rect.Max .x = ImMin (cell_bg_rect.Max .x , table-> Columns [cell_data-> Column ]. ClipRect .Max .x );
1766
+ cell_bg_rect.Min .x = ImMax (cell_bg_rect.Min .x , column-> ClipRect .Min .x ); // So that first column after frozen one gets clipped
1767
+ cell_bg_rect.Max .x = ImMin (cell_bg_rect.Max .x , column-> ClipRect .Max .x );
1812
1768
window->DrawList ->AddRectFilled (cell_bg_rect.Min , cell_bg_rect.Max , cell_data->BgColor );
1813
1769
}
1814
1770
}
@@ -1887,7 +1843,7 @@ void ImGui::TableBeginCell(ImGuiTable* table, int column_n)
1887
1843
1888
1844
window->WorkRect .Min .y = window->DC .CursorPos .y ;
1889
1845
window->WorkRect .Min .x = column->WorkMinX ;
1890
- window->WorkRect .Max .x = column->MaxX - table-> CellPaddingX - table-> CellSpacingX2 ;
1846
+ window->WorkRect .Max .x = column->WorkMaxX ;
1891
1847
1892
1848
// To allow ImGuiListClipper to function we propagate our row height
1893
1849
if (!column->IsVisible )
@@ -2962,26 +2918,27 @@ void ImGui::DebugNodeTable(ImGuiTable* table)
2962
2918
if (!open)
2963
2919
return ;
2964
2920
BulletText (" OuterRect: Pos: (%.1f,%.1f) Size: (%.1f,%.1f)" , table->OuterRect .Min .x , table->OuterRect .Min .y , table->OuterRect .GetWidth (), table->OuterRect .GetHeight ());
2965
- BulletText (" InnerWidth: %.1f%s" , table->InnerWidth , table->InnerWidth == 0 .0f ? " (auto)" : " " );
2966
- BulletText (" ColumnsWidth: %.1f, AutoFitWidth: %.1f" , table->ColumnsTotalWidth , table->ColumnsAutoFitWidth );
2921
+ BulletText (" ColumnsWidth: %.1f, AutoFitWidth: %.1f, InnerWidth: %.1f%s" , table->ColumnsTotalWidth , table->ColumnsAutoFitWidth , table->InnerWidth , table->InnerWidth == 0 .0f ? " (auto)" : " " );
2967
2922
BulletText (" CellPaddingX: %.1f, CellSpacingX: %.1f/%.1f, OuterPaddingX: %.1f" , table->CellPaddingX , table->CellSpacingX1 , table->CellSpacingX2 , table->OuterPaddingX );
2968
2923
BulletText (" HoveredColumnBody: %d, HoveredColumnBorder: %d" , table->HoveredColumnBody , table->HoveredColumnBorder );
2969
2924
BulletText (" ResizedColumn: %d, ReorderColumn: %d, HeldHeaderColumn: %d" , table->ResizedColumn , table->ReorderColumn , table->HeldHeaderColumn );
2970
- BulletText (" BgDrawChannels: %d/%d" , 0 , table->BgDrawChannelUnfrozen );
2925
+ // BulletText("BgDrawChannels: %d/%d", 0, table->BgDrawChannelUnfrozen);
2971
2926
for (int n = 0 ; n < table->ColumnsCount ; n++)
2972
2927
{
2973
2928
ImGuiTableColumn* column = &table->Columns [n];
2974
2929
const char * name = TableGetColumnName (table, n);
2975
2930
ImFormatString (buf, IM_ARRAYSIZE (buf),
2976
- " Column %d order %d name '%s': +%.1f to +%.1f \n "
2931
+ " Column %d order %d name '%s': offset %+.2f to %+.2f \n "
2977
2932
" Visible: %d, Clipped: %d, DrawChannels: %d,%d\n "
2978
- " WidthGiven: %.2f, Request/Auto: %.2f/%.2f, StretchWeight: %.3f\n "
2979
- " ContentWidth: %.2f,%.2f, HeadersUsed/Ideal %.2f/%.2f\n "
2933
+ " WidthGiven: %.1f, Request/Auto: %.1f/%.1f, StretchWeight: %.3f\n "
2934
+ " MinX: %.1f, MaxX: %.1f (%+.1f), ClipRect: %.1f to %.1f (+%.1f)\n "
2935
+ " ContentWidth: %.1f,%.1f, HeadersUsed/Ideal %.1f/%.1f\n "
2980
2936
" SortOrder: %d, SortDir: %s\n "
2981
2937
" UserID: 0x%08X, Flags: 0x%04X: %s%s%s%s.." ,
2982
2938
n, column->DisplayOrder , name, column->MinX - table->WorkRect .Min .x , column->MaxX - table->WorkRect .Min .x ,
2983
2939
column->IsVisible , column->IsClipped , column->DrawChannelFrozen , column->DrawChannelUnfrozen ,
2984
2940
column->WidthGiven , column->WidthRequest , column->WidthAuto , column->StretchWeight ,
2941
+ column->MinX , column->MaxX , column->MaxX - column->MinX , column->ClipRect .Min .x , column->ClipRect .Max .x , column->ClipRect .Max .x - column->ClipRect .Min .x ,
2985
2942
column->ContentMaxXFrozen - column->WorkMinX , column->ContentMaxXUnfrozen - column->WorkMinX , column->ContentMaxXHeadersUsed - column->WorkMinX , column->ContentMaxXHeadersIdeal - column->WorkMinX ,
2986
2943
column->SortOrder , (column->SortDirection == ImGuiSortDirection_Ascending) ? " Ascending" : (column->SortDirection == ImGuiSortDirection_Descending) ? " Descending" : " None" ,
2987
2944
column->UserID , column->Flags ,
0 commit comments