96
96
static const int TABLE_DRAW_CHANNEL_BG0 = 0 ;
97
97
static const int TABLE_DRAW_CHANNEL_BG1_FROZEN = 1 ;
98
98
static const int TABLE_DRAW_CHANNEL_UNCLIPPED = 2 ; // When using ImGuiTableFlags_NoClip
99
- static const float TABLE_BORDER_SIZE = 1 .0f ; // FIXME-TABLE: Currently hard-coded.
99
+ static const float TABLE_BORDER_SIZE = 1 .0f ; // FIXME-TABLE: Currently hard-coded because of clipping assumptions with outer borders rendering .
100
100
static const float TABLE_RESIZE_SEPARATOR_HALF_THICKNESS = 4 .0f ; // Extend outside inner borders.
101
101
static const float TABLE_RESIZE_SEPARATOR_FEEDBACK_TIMER = 0 .06f ; // Delay/timer before making the hover feedback (color+cursor) visible because tables/columns tends to be more cramped.
102
102
@@ -616,7 +616,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
616
616
// (can't make auto padding larger than what WorkRect knows about so right-alignment matches)
617
617
const ImRect work_rect = table->WorkRect ;
618
618
const float min_column_width = TableGetMinColumnWidth ();
619
- const float min_column_distance = min_column_width + table->CellPaddingX * 2 .0f ;
619
+ const float min_column_distance = min_column_width + table->CellPaddingX * 2 .0f + table-> CellSpacingX1 + table-> CellSpacingX2 ;
620
620
621
621
int count_fixed = 0 ;
622
622
float sum_weights_stretched = 0 .0f ; // Sum of all weights for weighted columns.
@@ -668,7 +668,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
668
668
// This is merely making the side-effect less extreme, but doesn't properly fixes it.
669
669
// FIXME: Move this to ->WidthGiven to avoid temporary lossyless?
670
670
if (column->AutoFitQueue > 0x01 && table->IsInitializing )
671
- column->WidthRequest = ImMax (column->WidthRequest , min_column_width * 4 .0f );
671
+ column->WidthRequest = ImMax (column->WidthRequest , min_column_width * 4 .0f ); // FIXME-TABLE: Another constant/scale?
672
672
673
673
count_fixed += 1 ;
674
674
sum_width_fixed_requests += column->WidthRequest ;
@@ -763,6 +763,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
763
763
offset_x += table->OuterPaddingX ;
764
764
offset_x -= table->CellSpacingX1 ;
765
765
ImRect host_clip_rect = table->InnerClipRect ;
766
+ // host_clip_rect.Max.x += table->CellPaddingX + table->CellSpacingX2;
766
767
for (int order_n = 0 ; order_n < table->ColumnsCount ; order_n++)
767
768
{
768
769
const int column_n = table->DisplayOrderToIndex [order_n];
@@ -786,31 +787,46 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
786
787
continue ;
787
788
}
788
789
789
- float max_x = FLT_MAX;
790
+ // Maximum width
791
+ float max_width = FLT_MAX;
790
792
if (table->Flags & ImGuiTableFlags_ScrollX)
791
793
{
792
794
// Frozen columns can't reach beyond visible width else scrolling will naturally break.
793
795
if (order_n < table->FreezeColumnsRequest )
794
- max_x = table->InnerClipRect .Max .x - (table->FreezeColumnsRequest - order_n) * min_column_distance - table->OuterPaddingX ;
796
+ {
797
+ max_width = (table->InnerClipRect .Max .x - (table->FreezeColumnsRequest - order_n) * min_column_distance) - offset_x;
798
+ max_width = max_width - table->OuterPaddingX - table->CellPaddingX - table->CellSpacingX2 ;
799
+ }
795
800
}
796
801
else if ((table->Flags & ImGuiTableFlags_NoKeepColumnsVisible) == 0 )
797
802
{
798
803
// If horizontal scrolling if disabled, we apply a final lossless shrinking of columns in order to make
799
804
// sure they are all visible. Because of this we also know that all of the columns will always fit in
800
805
// table->WorkRect and therefore in table->InnerRect (because ScrollX is off)
801
- max_x = table->WorkRect .Max .x - (table->ColumnsVisibleCount - (column->IndexWithinVisibleSet + 1 )) * min_column_distance - table->OuterPaddingX ;
806
+ // FIXME-TABLE: This is solved incorrectly but also quite a difficult problem to fix as we also want ClipRect width to match.
807
+ // See "table_width_distrib" and "table_width_keep_visible" tests
808
+ max_width = table->WorkRect .Max .x - (table->ColumnsVisibleCount - column->IndexWithinVisibleSet - 1 ) * min_column_distance - offset_x;
809
+ // max_width -= table->CellSpacingX1;
810
+ max_width -= table->CellSpacingX2 ;
811
+ max_width -= table->CellPaddingX * 2 .0f ;
812
+ max_width -= table->OuterPaddingX ;
802
813
}
803
- if (offset_x + column->WidthGiven + table->CellPaddingX * 2 .0f + table->CellSpacingX1 > max_x)
804
- column->WidthGiven = ImMax (max_x - offset_x - table->CellPaddingX * 2 .0f - table->CellSpacingX1 , min_column_width);
814
+ column->WidthGiven = ImMin (column->WidthGiven , max_width);
815
+
816
+ // Minimum width
817
+ column->WidthGiven = ImMax (column->WidthGiven , ImMin (column->WidthRequest , min_column_width));
805
818
806
819
// Lock all our positions
820
+ // - ClipRect.Min.x: Because merging draw commands doesn't compare min boundaries, we make ClipRect.Min.x match left bounds to be consistent regardless of merging.
821
+ // - ClipRect.Max.x: using WorkMaxX instead of MaxX (aka including padding) is detrimental to visibility in very-small column.
822
+ // - FIXME-TABLE: We want equal width columns to have equal (ClipRect.Max.x - WorkMinX) width, which means ClipRect.max.x cannot stray off host_clip_rect.Max.x else right-most column may appear shorter.
807
823
column->MinX = offset_x;
808
824
column->MaxX = offset_x + column->WidthGiven + table->CellSpacingX1 + table->CellSpacingX2 + table->CellPaddingX * 2 .0f ;
809
825
column->WorkMinX = column->MinX + table->CellPaddingX + table->CellSpacingX1 ;
810
826
column->WorkMaxX = column->MaxX - table->CellPaddingX - table->CellSpacingX2 ; // Expected max
811
827
column->ClipRect .Min .x = column->MinX ;
812
828
column->ClipRect .Min .y = work_rect.Min .y ;
813
- column->ClipRect .Max .x = column->MaxX ;
829
+ column->ClipRect .Max .x = column->MaxX ; // column->WorkMaxX;
814
830
column->ClipRect .Max .y = FLT_MAX;
815
831
column->ClipRect .ClipWithFull (host_clip_rect);
816
832
@@ -845,7 +861,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
845
861
}
846
862
847
863
if (visible_n < table->FreezeColumnsCount )
848
- host_clip_rect.Min .x = ImMax (host_clip_rect.Min .x , column->MaxX + 2 . 0f );
864
+ host_clip_rect.Min .x = ImMax (host_clip_rect.Min .x , column->MaxX + TABLE_BORDER_SIZE );
849
865
850
866
offset_x += column->WidthGiven + table->CellSpacingX1 + table->CellSpacingX2 + table->CellPaddingX * 2 .0f ;
851
867
visible_n++;
@@ -1031,7 +1047,7 @@ void ImGui::EndTable()
1031
1047
#if 0
1032
1048
// Strip out dummy channel draw calls
1033
1049
// We have no way to prevent user submitting direct ImDrawList calls into a hidden column (but ImGui:: calls will be clipped out)
1034
- // FIXME-TABLE: The problem with this approach is we are effectively making it harder for users watching metrics to spot wasted vertices.
1050
+ // ( The problem with this approach is we are effectively making it harder for users watching metrics to spot wasted vertices)
1035
1051
if (table->DummyDrawChannel != (ImU8)-1)
1036
1052
{
1037
1053
ImDrawChannel* dummy_channel = &table->DrawSplitter._Channels[table->DummyDrawChannel];
@@ -1169,6 +1185,7 @@ void ImGui::TableDrawBorders(ImGuiTable* table)
1169
1185
}
1170
1186
1171
1187
// Draw outer border
1188
+ // FIXME-TABLE: could use AddRect or explicit VLine/HLine helper?
1172
1189
if (table->Flags & ImGuiTableFlags_BordersOuter)
1173
1190
{
1174
1191
// Display outer border offset by 1 which is a simple way to display it without adding an extra draw call
@@ -1186,7 +1203,6 @@ void ImGui::TableDrawBorders(ImGuiTable* table)
1186
1203
}
1187
1204
else if (table->Flags & ImGuiTableFlags_BordersOuterV)
1188
1205
{
1189
- // FIXME-TABLE: could use AddRect or explicit VLine/HLine helper?
1190
1206
outer_drawlist->AddLine (outer_border.Min , ImVec2 (outer_border.Min .x , outer_border.Max .y ), outer_col, border_size);
1191
1207
outer_drawlist->AddLine (ImVec2 (outer_border.Max .x , outer_border.Min .y ), outer_border.Max , outer_col, border_size);
1192
1208
}
@@ -1199,7 +1215,6 @@ void ImGui::TableDrawBorders(ImGuiTable* table)
1199
1215
if ((table->Flags & ImGuiTableFlags_BordersInnerH) && table->RowPosY2 < table->OuterRect .Max .y )
1200
1216
{
1201
1217
// Draw bottom-most row border
1202
- // FIXME-TABLE: could use AddRect or explicit VLine/HLine helper?
1203
1218
const float border_y = table->RowPosY2 ;
1204
1219
if (border_y >= table->BgClipRect .Min .y && border_y < table->BgClipRect .Max .y )
1205
1220
inner_drawlist->AddLine (ImVec2 (table->BorderX1 , border_y), ImVec2 (table->BorderX2 , border_y), table->BorderColorLight , border_size);
@@ -1790,7 +1805,7 @@ void ImGui::TableEndRow(ImGuiTable* table)
1790
1805
ImRect cell_bg_rect = TableGetCellBgRect (table, cell_data->Column );
1791
1806
cell_bg_rect.ClipWith (table->BgClipRect );
1792
1807
cell_bg_rect.Min .x = ImMax (cell_bg_rect.Min .x , column->ClipRect .Min .x ); // So that first column after frozen one gets clipped
1793
- cell_bg_rect.Max .x = ImMin (cell_bg_rect.Max .x , column->ClipRect . Max . x );
1808
+ cell_bg_rect.Max .x = ImMin (cell_bg_rect.Max .x , column->MaxX );
1794
1809
window->DrawList ->AddRectFilled (cell_bg_rect.Min , cell_bg_rect.Max , cell_data->BgColor );
1795
1810
}
1796
1811
}
@@ -1911,7 +1926,6 @@ void ImGui::TableEndCell(ImGuiTable* table)
1911
1926
}
1912
1927
1913
1928
// Append into the next column/cell
1914
- // FIXME-TABLE: Wrapping to next row could be optional?
1915
1929
bool ImGui::TableNextColumn ()
1916
1930
{
1917
1931
ImGuiContext& g = *GImGui;
@@ -2365,7 +2379,7 @@ void ImGui::TableHeader(const char* label)
2365
2379
2366
2380
// We feed our unclipped width to the column without writing on CursorMaxPos, so that column is still considering for merging.
2367
2381
float max_pos_x = label_pos.x + label_size.x + w_sort_text + w_arrow;
2368
- column->ContentMaxXHeadersUsed = ImMax (column->ContentMaxXHeadersUsed , cell_r. Max . x );
2382
+ column->ContentMaxXHeadersUsed = ImMax (column->ContentMaxXHeadersUsed , column-> WorkMaxX );
2369
2383
column->ContentMaxXHeadersIdeal = ImMax (column->ContentMaxXHeadersIdeal , max_pos_x);
2370
2384
2371
2385
// We don't use BeginPopupContextItem() because we want the popup to stay up even after the column is hidden
0 commit comments