Tables: fixed ColumnsAutoFitWidth for resizable fixed columns reporting ideal width.

This commit is contained in:
ocornut 2021-01-15 17:48:15 +01:00
parent 3e712631da
commit 4d419d1211
2 changed files with 9 additions and 3 deletions

View File

@ -4600,7 +4600,7 @@ static void ShowDemoWindowTables()
static ImGuiTableFlags flags1 = ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders | ImGuiTableFlags_ContextMenuInBody; static ImGuiTableFlags flags1 = ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders | ImGuiTableFlags_ContextMenuInBody;
PushStyleCompact(); PushStyleCompact();
ImGui::CheckboxFlags("ImGuiTableFlags_ContextMenuInBody", (unsigned int*)&flags1, ImGuiTableFlags_ContextMenuInBody); ImGui::CheckboxFlags("ImGuiTableFlags_ContextMenuInBody", &flags1, ImGuiTableFlags_ContextMenuInBody);
PopStyleCompact(); PopStyleCompact();
// Context Menus: first example // Context Menus: first example

View File

@ -1234,7 +1234,13 @@ void ImGui::EndTable()
table->ColumnsAutoFitWidth = width_spacings + (table->CellPaddingX * 2.0f) * table->ColumnsEnabledCount; table->ColumnsAutoFitWidth = width_spacings + (table->CellPaddingX * 2.0f) * table->ColumnsEnabledCount;
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
if (table->EnabledMaskByIndex & ((ImU64)1 << column_n)) if (table->EnabledMaskByIndex & ((ImU64)1 << column_n))
table->ColumnsAutoFitWidth += TableGetColumnWidthAuto(table, &table->Columns[column_n]); {
ImGuiTableColumn* column = &table->Columns[column_n];
if ((column->Flags & ImGuiTableColumnFlags_WidthFixed) && !(column->Flags & ImGuiTableColumnFlags_NoResize))
table->ColumnsAutoFitWidth += column->WidthRequest;
else
table->ColumnsAutoFitWidth += TableGetColumnWidthAuto(table, column);
}
// Update scroll // Update scroll
if ((table->Flags & ImGuiTableFlags_ScrollX) == 0 && inner_window != outer_window) if ((table->Flags & ImGuiTableFlags_ScrollX) == 0 && inner_window != outer_window)
@ -1457,7 +1463,7 @@ ImRect ImGui::TableGetCellBgRect(const ImGuiTable* table, int column_n)
// Return the resizing ID for the right-side of the given column. // Return the resizing ID for the right-side of the given column.
ImGuiID ImGui::TableGetColumnResizeID(const ImGuiTable* table, int column_n, int instance_no) ImGuiID ImGui::TableGetColumnResizeID(const ImGuiTable* table, int column_n, int instance_no)
{ {
IM_ASSERT(column_n < table->ColumnsCount); IM_ASSERT(column_n >= 0 && column_n < table->ColumnsCount);
ImGuiID id = table->ID + 1 + (instance_no * table->ColumnsCount) + column_n; ImGuiID id = table->ID + 1 + (instance_no * table->ColumnsCount) + column_n;
return id; return id;
} }