diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index bbd5e0ba4..800fce8c5 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -66,6 +66,8 @@ Autumn cleanup of stuff marked obsolete more than two years ago: Other Changes: +- Tables: added a context-menu option to reset column sizing to the values passed to `TableSetupColumn()`. + Renamed "Size all columns to default" to "Size all columns to fit" to clarify that it performs content fitting. - Style: - `StyleColorsDark()`: tweaked WindowBg to be darker than in 1.93.0. - Added `style.SymbolArrowSizeFactor`, `style.SymbolArrowThicknessFactor` to tweak the diff --git a/imgui.cpp b/imgui.cpp index 4519c96fb..d0db69320 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4305,9 +4305,10 @@ static const ImGuiLocEntry GLocalizationEntriesEnUS[] = { ImGuiLocKey_VersionStr, "Dear ImGui " IMGUI_VERSION " (" IM_STRINGIFY(IMGUI_VERSION_NUM) ")" }, { ImGuiLocKey_TableSizeOne, "Size column to fit###SizeOne" }, { ImGuiLocKey_TableSizeAllFit, "Size all columns to fit###SizeAll" }, - { ImGuiLocKey_TableSizeAllDefault, "Size all columns to default###SizeAll" }, + { ImGuiLocKey_TableSizeAllDefault, "Size all columns to fit###SizeAll" }, { ImGuiLocKey_TableReset, "Reset" }, //{ ImGuiLocKey_TableResetAll, "Reset to default###ResetAll" }, + { ImGuiLocKey_TableResetSizing, "Reset column sizing###ResetSizing" }, { ImGuiLocKey_TableResetOrder, "Reset order###ResetOrder" }, { ImGuiLocKey_TableResetVisibility, "Reset visibility###ResetVisibility" }, { ImGuiLocKey_WindowingMainMenuBar, "(Main menu bar)" }, diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 5545ecc41..d107bd67f 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -7383,13 +7383,14 @@ static void DemoWindowTables() // [2.3] Right-click in columns to open another custom popup HelpMarker( "Demonstrate mixing table context menu (over header), item context button (over button) " - "and custom per-column context menu (over column body)."); + "and custom per-column context menu (over column body). The table context menu can reset " + "column sizing to the values passed to TableSetupColumn()."); ImGuiTableFlags flags2 = ImGuiTableFlags_Resizable | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders; if (ImGui::BeginTable("table_context_menu_2", COLUMNS_COUNT, flags2)) { - ImGui::TableSetupColumn("One"); - ImGui::TableSetupColumn("Two"); - ImGui::TableSetupColumn("Three"); + ImGui::TableSetupColumn("One", ImGuiTableColumnFlags_WidthFixed, 100.0f); + ImGui::TableSetupColumn("Two", ImGuiTableColumnFlags_WidthFixed, 140.0f); + ImGui::TableSetupColumn("Three", ImGuiTableColumnFlags_WidthStretch, 1.0f); // [2.1] Right-click on the TableHeadersRow() line to open the default table context menu. ImGui::TableHeadersRow(); diff --git a/imgui_internal.h b/imgui_internal.h index 57851e7ee..1435539e1 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -2156,6 +2156,7 @@ enum ImGuiLocKey : int ImGuiLocKey_TableSizeAllDefault, ImGuiLocKey_TableReset, //ImGuiLocKey_TableResetAll, + ImGuiLocKey_TableResetSizing, ImGuiLocKey_TableResetOrder, ImGuiLocKey_TableResetVisibility, ImGuiLocKey_WindowingMainMenuBar, @@ -3236,6 +3237,7 @@ struct IMGUI_API ImGuiTable bool IsDefaultDisplayOrder; // Set when display order is unchanged from default (DisplayOrder contains 0...Count-1) bool IsDefaultVisibility; // Set when enabled/visibility is unchanged from default bool IsResetAllRequest; // Set to queue a call to TableResetSettings() in BeginTable() + bool IsResetSizingRequest; // Set to restore sizing from TableSetupColumn() values bool IsResetDisplayOrderRequest; bool IsResetVisibilityRequest; bool IsUnfrozenRows; // Set when we got past the frozen row. diff --git a/imgui_tables.cpp b/imgui_tables.cpp index f7a39f689..b61c1f130 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -720,6 +720,13 @@ void ImGui::TableApplyQueuedRequests(ImGuiTable* table) table->IsResetVisibilityRequest = false; table->IsSettingsDirty = true; } + if (table->IsResetSizingRequest) + { + for (ImGuiTableColumn& column : table->Columns) + TableInitColumnDefaults(table, &column, ImGuiTableFlags_Resizable); + table->IsResetSizingRequest = false; + table->IsSettingsDirty = true; + } } // Apply immediately. See TableQueueSetColumnDisplayOrder() for additional checks/constraints. @@ -3722,8 +3729,8 @@ static bool MenuItemForColumnReorder(const char* label, bool selected, bool enab // Output context menu into current window (generally a popup) // FIXME-TABLE: Ideally this should be writable by the user. Full programmatic access to that data? // Sections to display are pulled from 'flags_for_section_to_display', which is typically == table->Flags. -// - ImGuiTableFlags_Resizable -> display Sizing menu items -// - ImGuiTableFlags_Reorderable -> display "Reset Order" +// - ImGuiTableFlags_Resizable -> display Sizing menu items and "Reset column sizing" +// - ImGuiTableFlags_Reorderable -> display "Reset order" ////- ImGuiTableFlags_Sortable -> display sorting options (disabled) // - ImGuiTableFlags_Hideable -> display columns visibility menu items // It means if you have a custom context menus you can call this section and omit some sections, and add your own. @@ -3758,12 +3765,15 @@ void ImGui::TableDrawDefaultContextMenu(ImGuiTable* table, ImGuiTableFlags flags want_separator = true; } - // Reset Order/Visibility etc. - if (flags_for_section_to_display & (ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable)) + // Reset sizing/order/visibility etc. + if (flags_for_section_to_display & (ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable)) if (BeginMenu(LocalizeGetMsg(ImGuiLocKey_TableReset))) { //if (MenuItem(LocalizeGetMsg(ImGuiLocKey_TableResetAll))) // FIXME: Hiding because altering Sort Order + requesting auto-fit simultaneously has a tendency to exhibit a sizing glitch. // table->IsResetAllRequest = true; + if (flags_for_section_to_display & ImGuiTableFlags_Resizable) + if (MenuItem(LocalizeGetMsg(ImGuiLocKey_TableResetSizing))) + table->IsResetSizingRequest = true; if (flags_for_section_to_display & ImGuiTableFlags_Reorderable) if (MenuItem(LocalizeGetMsg(ImGuiLocKey_TableResetOrder), NULL, false, !table->IsDefaultDisplayOrder)) // PS: cannot be hidden because it would mess with drag reordering. table->IsResetDisplayOrderRequest = true;