diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 192a30523..4f600ed78 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -55,6 +55,9 @@ Other Changes: - InputText: - Added `style.InputTextCursorSize` to configure cursor/caret thickness. (#7031, #9409) This is automatically scaled by `style.ScaleAllSizes()`. +- Tables: + - Context Menu: added a "Reset" sub-menu with a "Reset Visibility" option. + (which is greyed out when using default settings) - Fonts: - Added `IMGUI_DISABLE_DEFAULT_FONT_BITMAP`/`IMGUI_DISABLE_DEFAULT_FONT_VECTOR` to disable embedding either fonts separately. (#9407) diff --git a/imgui.cpp b/imgui.cpp index 516bd9dec..1e2817136 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4161,7 +4161,10 @@ static const ImGuiLocEntry GLocalizationEntriesEnUS[] = { ImGuiLocKey_TableSizeOne, "Size column to fit###SizeOne" }, { ImGuiLocKey_TableSizeAllFit, "Size all columns to fit###SizeAll" }, { ImGuiLocKey_TableSizeAllDefault, "Size all columns to default###SizeAll" }, + { ImGuiLocKey_TableReset, "Reset" }, + //{ ImGuiLocKey_TableResetAll, "Reset to default###ResetAll" }, { ImGuiLocKey_TableResetOrder, "Reset order###ResetOrder" }, + { ImGuiLocKey_TableResetVisibility, "Reset visibility###ResetVisibility" }, { ImGuiLocKey_WindowingMainMenuBar, "(Main menu bar)" }, { ImGuiLocKey_WindowingPopup, "(Popup)" }, { ImGuiLocKey_WindowingUntitled, "(Untitled)" }, diff --git a/imgui.h b/imgui.h index cd6cb2446..88419d6f8 100644 --- a/imgui.h +++ b/imgui.h @@ -30,7 +30,7 @@ // Library Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345') #define IMGUI_VERSION "1.92.9 WIP" -#define IMGUI_VERSION_NUM 19282 +#define IMGUI_VERSION_NUM 19283 #define IMGUI_HAS_TABLE // Added BeginTable() - from IMGUI_VERSION_NUM >= 18000 #define IMGUI_HAS_TEXTURES // Added ImGuiBackendFlags_RendererHasTextures - from IMGUI_VERSION_NUM >= 19198 diff --git a/imgui_internal.h b/imgui_internal.h index a843e4767..0c95dd23e 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -2047,7 +2047,10 @@ enum ImGuiLocKey : int ImGuiLocKey_TableSizeOne, ImGuiLocKey_TableSizeAllFit, ImGuiLocKey_TableSizeAllDefault, + ImGuiLocKey_TableReset, + //ImGuiLocKey_TableResetAll, ImGuiLocKey_TableResetOrder, + ImGuiLocKey_TableResetVisibility, ImGuiLocKey_WindowingMainMenuBar, ImGuiLocKey_WindowingPopup, ImGuiLocKey_WindowingUntitled, @@ -3086,8 +3089,10 @@ struct IMGUI_API ImGuiTable bool IsSettingsRequestLoad; bool IsSettingsDirty; // Set when table settings have changed and needs to be reported into ImGuiTableSettings data. bool IsDefaultDisplayOrder; // Set when display order is unchanged from default (DisplayOrder contains 0...Count-1) - bool IsResetAllRequest; + bool IsDefaultVisibility; // Set when enabled/visibility is unchanged from default + bool IsResetAllRequest; // Set to queue a call to TableResetSettings() in BeginTable() bool IsResetDisplayOrderRequest; + bool IsResetVisibilityRequest; bool IsUnfrozenRows; // Set when we got past the frozen row. bool IsDefaultSizingPolicy; // Set if user didn't explicitly set a sizing policy in BeginTable() bool IsActiveIdAliveBeforeTable; diff --git a/imgui_tables.cpp b/imgui_tables.cpp index 3e3247806..a306a0077 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -704,7 +704,7 @@ void ImGui::TableBeginApplyRequests(ImGuiTable* table) // table->ReorderColumn = -1; } - // Handle display order reset request + // Handle display order / visibility reset requests if (table->IsResetDisplayOrderRequest) { for (int n = 0; n < table->ColumnsCount; n++) @@ -712,6 +712,13 @@ void ImGui::TableBeginApplyRequests(ImGuiTable* table) table->IsResetDisplayOrderRequest = false; table->IsSettingsDirty = true; } + if (table->IsResetVisibilityRequest) + { + for (ImGuiTableColumn& column : table->Columns) + column.IsUserEnabled = column.IsUserEnabledNextFrame = (column.Flags & ImGuiTableColumnFlags_DefaultHide) ? 0 : 1; + table->IsResetVisibilityRequest = false; + table->IsSettingsDirty = true; + } } // Apply immediately. See TableQueueSetColumnDisplayOrder() for additional checks/constraints. @@ -853,7 +860,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) table->RefScale = new_ref_scale_unit; const ImGuiTableFlags table_sizing_policy = (table->Flags & ImGuiTableFlags_SizingMask_); - table->IsDefaultDisplayOrder = true; + table->IsDefaultDisplayOrder = table->IsDefaultVisibility = true; table->ColumnsEnabledCount = 0; ImBitArrayClearAllBits(table->EnabledMaskByIndex, columns_count); ImBitArrayClearAllBits(table->EnabledMaskByDisplayOrder, columns_count); @@ -872,8 +879,6 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) for (int order_n = 0; order_n < columns_count; order_n++) { const int column_n = table->DisplayOrderToIndex[order_n]; - if (column_n != order_n) - table->IsDefaultDisplayOrder = false; ImGuiTableColumn* column = &table->Columns[column_n]; // Clear column setup if not submitted by user. Currently we make it mandatory to call TableSetupColumn() every frame. @@ -897,6 +902,11 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) } column->IsEnabled = column->IsUserEnabled && (column->Flags & ImGuiTableColumnFlags_Disabled) == 0; + if (column->IsEnabled != ((column->Flags & ImGuiTableColumnFlags_DefaultHide) ? 0 : 1)) + table->IsDefaultVisibility = false; + if (column_n != order_n) + table->IsDefaultDisplayOrder = false; + if (column->SortOrder != -1 && !column->IsEnabled) table->IsSortSpecsDirty = true; if (column->SortOrder > 0 && !(table->Flags & ImGuiTableFlags_SortMulti)) @@ -3598,17 +3608,20 @@ void ImGui::TableDrawDefaultContextMenu(ImGuiTable* table, ImGuiTableFlags flags want_separator = true; } - // Ordering - if (flags_for_section_to_display & ImGuiTableFlags_Reorderable) - { - if (MenuItem(LocalizeGetMsg(ImGuiLocKey_TableResetOrder), NULL, false, !table->IsDefaultDisplayOrder)) - table->IsResetDisplayOrderRequest = true; - want_separator = true; - } - - // Reset all (should work but seems unnecessary/noisy to expose?) - //if (MenuItem("Reset all")) - // table->IsResetAllRequest = true; + // Reset Order/Visibility etc. + if (flags_for_section_to_display & (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_Reorderable) + if (MenuItem(LocalizeGetMsg(ImGuiLocKey_TableResetOrder), NULL, false, !table->IsDefaultDisplayOrder)) // PS: cannot be hidden because it would mess with drag reordering. + table->IsResetDisplayOrderRequest = true; + if (flags_for_section_to_display & ImGuiTableFlags_Hideable) + if (MenuItem(LocalizeGetMsg(ImGuiLocKey_TableResetVisibility), NULL, false, !table->IsDefaultVisibility)) + table->IsResetVisibilityRequest = true; + EndMenu(); + } // Sorting // (modify TableOpenContextMenu() to add _Sortable flag if enabling this) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 6a6605279..4ea116234 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -9638,7 +9638,7 @@ bool ImGui::MenuItemEx(const char* label, const char* icon, const char* shortcut // Only when they are other items sticking out we're going to add spacing, yet only register minimum width into the layout system.) float icon_w = (icon && icon[0]) ? CalcTextSize(icon, NULL).x : 0.0f; float shortcut_w = (shortcut && shortcut[0]) ? CalcTextSize(shortcut, NULL).x : 0.0f; - float checkmark_w = IM_TRUNC(g.FontSize * 1.20f); + float checkmark_w = IM_TRUNC(g.FontSize * 1.20f); // FIXME: Always accounted for, even in a menu with none, because 'selected' has no neutral setting. float min_w = offsets->DeclColumns(icon_w, label_size.x, shortcut_w, checkmark_w); // Feedback for next frame float stretch_w = ImMax(0.0f, GetContentRegionAvail().x - min_w); ImVec2 text_pos(pos.x, pos.y + window->DC.CurrLineTextBaseOffset);