Tables: workaround/hack for max width 1-off issue when right-most column is resizable. (#4678)

Requires !Scroll && Resizable && (NoHostExtendX || RightMostColumnnIsFixed) to see a difference.
This commit is contained in:
ocornut 2026-11-02 17:41:04 +01:00
parent c5131aff7e
commit 67f442d5de

View File

@ -2415,7 +2415,7 @@ void ImGui::TableEndCell(ImGuiTable* table)
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// [SECTION] Tables: Columns width management // [SECTION] Tables: Columns width management
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// - TableGetMaxColumnWidth() [Internal] // - TableCalcMaxColumnWidth() [Internal]
// - TableGetColumnWidthAuto() [Internal] // - TableGetColumnWidthAuto() [Internal]
// - TableSetColumnWidth() // - TableSetColumnWidth()
// - TableSetColumnWidthAutoSingle() [Internal] // - TableSetColumnWidthAutoSingle() [Internal]
@ -3012,14 +3012,21 @@ void ImGui::TableDrawBorders(ImGuiTable* table)
const bool is_resized = (table->ResizedColumn == column_n) && (table->InstanceInteracted == table->InstanceCurrent); const bool is_resized = (table->ResizedColumn == column_n) && (table->InstanceInteracted == table->InstanceCurrent);
const bool is_resizable = (column->Flags & (ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_NoDirectResize_)) == 0; const bool is_resizable = (column->Flags & (ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_NoDirectResize_)) == 0;
const bool is_frozen_separator = (table->FreezeColumnsCount == order_n + 1); const bool is_frozen_separator = (table->FreezeColumnsCount == order_n + 1);
if (column->MaxX > table->InnerClipRect.Max.x && !is_resized)
// FIXME-TABLE: 1-off display hack for right-most column when resizable (!Scroll && Resizable && (NoHostExtendX || RightMostIsFixed)).
// Fixing actual width would involve altering width_avail in layout and TableCalcMaxColumnWidth(), which would drop the property
// ColumnsGivenWidth == Outer Allocated Width. Worth reworking, but would only make sense if we accept that BorderSize affects layout.
float draw_x2 = column->MaxX;
if (draw_x2 >= table->InnerClipRect.Max.x && draw_x2 - 1.0f <= table->InnerClipRect.Max.x)
draw_x2 = table->InnerClipRect.Max.x;
if (draw_x2 >= table->InnerClipRect.Max.x && !is_resized && !is_hovered)
continue; continue;
// Decide whether right-most column is visible // Decide whether right-most column is visible
if (column->NextEnabledColumn == -1 && !is_resizable) if (column->NextEnabledColumn == -1 && !is_resizable)
if ((table->Flags & ImGuiTableFlags_SizingMask_) != ImGuiTableFlags_SizingFixedSame || (table->Flags & ImGuiTableFlags_NoHostExtendX)) if ((table->Flags & ImGuiTableFlags_SizingMask_) != ImGuiTableFlags_SizingFixedSame || (table->Flags & ImGuiTableFlags_NoHostExtendX))
continue; continue;
if (column->MaxX <= column->ClipRect.Min.x) // FIXME-TABLE FIXME-STYLE: Assume BorderSize==1, this is problematic if we want to increase the border size.. if (draw_x2 <= column->ClipRect.Min.x) // FIXME-TABLE FIXME-STYLE: Assume BorderSize==1, this is problematic if we want to increase the border size..
continue; continue;
// Draw in outer window so right-most column won't be clipped // Draw in outer window so right-most column won't be clipped
@ -3031,7 +3038,7 @@ void ImGui::TableDrawBorders(ImGuiTable* table)
else if ((table->Flags & (ImGuiTableFlags_NoBordersInBodyUntilResize | ImGuiTableFlags_NoBordersInBody)) == 0) else if ((table->Flags & (ImGuiTableFlags_NoBordersInBodyUntilResize | ImGuiTableFlags_NoBordersInBody)) == 0)
draw_y2 = draw_y2_body; draw_y2 = draw_y2_body;
if (draw_y2 > draw_y1) if (draw_y2 > draw_y1)
inner_drawlist->AddLineV(column->MaxX, draw_y1, draw_y2, TableGetColumnBorderCol(table, order_n, column_n), border_size_inner); inner_drawlist->AddLineV(draw_x2, draw_y1, draw_y2, TableGetColumnBorderCol(table, order_n, column_n), border_size_inner);
} }
} }