mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-13 00:09:55 +02:00
Tables: Fixed content size calculation creating feedback loops. Fixed handling of _DefaultSort with _PreferSortXXXflags (@parbo). Comments.
This commit is contained in:
@ -487,6 +487,7 @@ static ImGuiTableColumnFlags TableFixColumnFlags(ImGuiTable* table, ImGuiTableCo
|
||||
// Sizing Policy
|
||||
if ((flags & ImGuiTableColumnFlags_WidthMask_) == 0)
|
||||
{
|
||||
// FIXME-TABLE: Inconsistent to promote columns to WidthAlwaysAutoResize
|
||||
if (table->Flags & ImGuiTableFlags_SizingPolicyFixedX)
|
||||
flags |= ((table->Flags & ImGuiTableFlags_Resizable) && !(flags & ImGuiTableColumnFlags_NoResize)) ? ImGuiTableColumnFlags_WidthFixed : ImGuiTableColumnFlags_WidthAlwaysAutoResize;
|
||||
else
|
||||
@ -536,7 +537,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
|
||||
|
||||
// Compute offset, clip rect for the frame
|
||||
const ImRect work_rect = table->WorkRect;
|
||||
const float padding_auto_x = table->CellPaddingX1; // Can't make auto padding larger than what WorkRect knows about so right-alignment matches.
|
||||
const float padding_auto_x = table->CellPaddingX2; // Can't make auto padding larger than what WorkRect knows about so right-alignment matches.
|
||||
const float min_column_width = TableGetMinColumnWidth();
|
||||
|
||||
int count_fixed = 0;
|
||||
@ -595,12 +596,13 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
|
||||
}
|
||||
|
||||
// Layout
|
||||
// Remove -1.0f to cancel out the +1.0f we are doing in EndTable() to make last column line visible
|
||||
const float width_spacings = table->CellSpacingX * (table->ColumnsActiveCount - 1);
|
||||
float width_avail;
|
||||
if ((table->Flags & ImGuiTableFlags_ScrollX) && (table->InnerWidth == 0.0f))
|
||||
width_avail = table->InnerClipRect.GetWidth() - width_spacings - 1.0f;
|
||||
else
|
||||
width_avail = work_rect.GetWidth() - width_spacings - 1.0f; // Remove -1.0f to cancel out the +1.0f we are doing in EndTable() to make last column line visible
|
||||
width_avail = work_rect.GetWidth() - width_spacings - 1.0f;
|
||||
const float width_avail_for_stretched_columns = width_avail - width_fixed;
|
||||
float width_remaining_for_stretched_columns = width_avail_for_stretched_columns;
|
||||
|
||||
@ -1406,7 +1408,10 @@ void ImGui::TableSetupColumn(const char* label, ImGuiTableColumnFlags flags,
|
||||
if (flags & ImGuiTableColumnFlags_DefaultHide)
|
||||
column->IsActive = column->NextIsActive = false;
|
||||
if (flags & ImGuiTableColumnFlags_DefaultSort)
|
||||
{
|
||||
column->SortOrder = 0; // Multiple columns using _DefaultSort will be reordered when building the sort specs.
|
||||
column->SortDirection = (column->Flags & ImGuiTableColumnFlags_PreferSortDescending) ? (ImS8)ImGuiSortDirection_Descending : (ImU8)(ImGuiSortDirection_Ascending);
|
||||
}
|
||||
}
|
||||
|
||||
// Store name (append with zero-terminator in contiguous buffer)
|
||||
@ -2090,7 +2095,7 @@ void ImGui::TableSortSpecsClickColumn(ImGuiTable* table, ImGuiTableColumn* click
|
||||
table->IsSortSpecsDirty = true;
|
||||
}
|
||||
|
||||
// Return NULL if no sort specs.
|
||||
// Return NULL if no sort specs (most often when ImGuiTableFlags_Sortable is not set)
|
||||
// You can sort your data again when 'SpecsChanged == true'. It will be true with sorting specs have changed since last call, or the first time.
|
||||
// Lifetime: don't hold on this pointer over multiple frames or past any subsequent call to BeginTable()!
|
||||
const ImGuiTableSortSpecs* ImGui::TableGetSortSpecs()
|
||||
@ -2439,10 +2444,12 @@ void ImGui::DebugNodeTable(ImGuiTable* table)
|
||||
BulletText("Column %d order %d name '%s': +%.1f to +%.1f\n"
|
||||
"Active: %d, Clipped: %d, DrawChannels: %d,%d\n"
|
||||
"WidthGiven/Requested: %.1f/%.1f, Weight: %.2f\n"
|
||||
"ContentWidth: RowsFrozen %d, RowsUnfrozen %d, HeadersUsed/Desired %d/%d\n"
|
||||
"UserID: 0x%08X, Flags: 0x%04X: %s%s%s%s..",
|
||||
n, column->IndexDisplayOrder, name ? name : "NULL", column->MinX - table->WorkRect.Min.x, column->MaxX - table->WorkRect.Min.x,
|
||||
column->IsActive, column->IsClipped, column->DrawChannelRowsBeforeFreeze, column->DrawChannelRowsAfterFreeze,
|
||||
column->WidthGiven, column->WidthRequested, column->ResizeWeight,
|
||||
column->ContentWidthRowsFrozen, column->ContentWidthRowsUnfrozen, column->ContentWidthHeadersUsed, column->ContentWidthHeadersDesired,
|
||||
column->UserID, column->Flags,
|
||||
(column->Flags & ImGuiTableColumnFlags_WidthFixed) ? "WidthFixed " : "",
|
||||
(column->Flags & ImGuiTableColumnFlags_WidthStretch) ? "WidthStretch " : "",
|
||||
|
Reference in New Issue
Block a user