Tables: Fixed ignoring DefaultHide or DefaultSort data from flags when loading settings that don't have them.

This commit is contained in:
omar 2020-05-13 13:30:41 +02:00 committed by ocornut
parent 9f43aae226
commit 9b6d0fdb7a
2 changed files with 9 additions and 11 deletions

View File

@ -1952,7 +1952,7 @@ struct ImGuiTable
ImU64 ActiveMaskByIndex; // Column Index -> IsActive map (Active == not hidden by user/api) in a format adequate for iterating column without touching cold data ImU64 ActiveMaskByIndex; // Column Index -> IsActive map (Active == not hidden by user/api) in a format adequate for iterating column without touching cold data
ImU64 ActiveMaskByDisplayOrder; // Column DisplayOrder -> IsActive map ImU64 ActiveMaskByDisplayOrder; // Column DisplayOrder -> IsActive map
ImU64 VisibleMaskByIndex; // Visible (== Active and not Clipped) ImU64 VisibleMaskByIndex; // Visible (== Active and not Clipped)
ImGuiTableFlags SettingsSaveFlags; // Pre-compute which data we are going to save into the .ini file (e.g. when order is not altered we won't save order) ImGuiTableFlags SettingsLoadedFlags; // Which data were loaded from the .ini file (e.g. when order is not altered we won't save order)
int SettingsOffset; // Offset in g.SettingsTables int SettingsOffset; // Offset in g.SettingsTables
int LastFrameActive; int LastFrameActive;
int ColumnsCount; // Number of columns declared in BeginTable() int ColumnsCount; // Number of columns declared in BeginTable()
@ -2022,7 +2022,6 @@ struct ImGuiTable
bool IsUsingHeaders; // Set when the first row had the ImGuiTableRowFlags_Headers flag. bool IsUsingHeaders; // Set when the first row had the ImGuiTableRowFlags_Headers flag.
bool IsContextPopupOpen; // Set when default context menu is open (also see: ContextPopupColumn, InstanceInteracted). bool IsContextPopupOpen; // Set when default context menu is open (also see: ContextPopupColumn, InstanceInteracted).
bool IsSettingsRequestLoad; bool IsSettingsRequestLoad;
bool IsSettingsLoaded;
bool IsSettingsDirty; // Set when table settings have changed and needs to be reported into ImGuiTableSetttings data. bool IsSettingsDirty; // Set when table settings have changed and needs to be reported into ImGuiTableSetttings data.
bool IsDefaultDisplayOrder; // Set when display order is unchanged from default (DisplayOrder contains 0...Count-1) bool IsDefaultDisplayOrder; // Set when display order is unchanged from default (DisplayOrder contains 0...Count-1)
bool IsResetDisplayOrderRequest; bool IsResetDisplayOrderRequest;
@ -2050,7 +2049,7 @@ struct ImGuiTableColumnSettings
ImS8 DisplayOrder; ImS8 DisplayOrder;
ImS8 SortOrder; ImS8 SortOrder;
ImS8 SortDirection : 7; ImS8 SortDirection : 7;
ImU8 Visible : 1; // This is called Active in ImGuiTableColumn, in .ini file we call it Visible. ImU8 Visible : 1; // This is called Active in ImGuiTableColumn, but in user-facing code we call this Visible (thus in .ini file)
ImGuiTableColumnSettings() ImGuiTableColumnSettings()
{ {

View File

@ -1466,12 +1466,12 @@ void ImGui::TableSetupColumn(const char* label, ImGuiTableColumnFlags flags,
column->ResizeWeight = 1.0f; column->ResizeWeight = 1.0f;
} }
} }
if (table->IsInitializing && !table->IsSettingsLoaded) if (table->IsInitializing)
{ {
// Init default visibility/sort state // Init default visibility/sort state
if (flags & ImGuiTableColumnFlags_DefaultHide) if ((flags & ImGuiTableColumnFlags_DefaultHide) && (table->SettingsLoadedFlags & ImGuiTableFlags_Hideable) == 0)
column->IsActive = column->IsActiveNextFrame = false; column->IsActive = column->IsActiveNextFrame = false;
if (flags & ImGuiTableColumnFlags_DefaultSort) if (flags & ImGuiTableColumnFlags_DefaultSort && (table->SettingsLoadedFlags & ImGuiTableFlags_Sortable) == 0)
{ {
column->SortOrder = 0; // Multiple columns using _DefaultSort will be reordered when building the sort specs. 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); column->SortDirection = (column->Flags & ImGuiTableColumnFlags_PreferSortDescending) ? (ImS8)ImGuiSortDirection_Descending : (ImU8)(ImGuiSortDirection_Ascending);
@ -2360,7 +2360,7 @@ void ImGui::TableSaveSettings(ImGuiTable* table)
} }
settings->ColumnsCount = (ImS8)table->ColumnsCount; settings->ColumnsCount = (ImS8)table->ColumnsCount;
// Serialize ImGuiTableSettings/ImGuiTableColumnSettings --> ImGuiTable/ImGuiTableColumn // Serialize ImGuiTable/ImGuiTableColumn into ImGuiTableSettings/ImGuiTableColumnSettings
IM_ASSERT(settings->ID == table->ID); IM_ASSERT(settings->ID == table->ID);
IM_ASSERT(settings->ColumnsCount == table->ColumnsCount && settings->ColumnsCountMax >= settings->ColumnsCount); IM_ASSERT(settings->ColumnsCount == table->ColumnsCount && settings->ColumnsCountMax >= settings->ColumnsCount);
ImGuiTableColumn* column = table->Columns.Data; ImGuiTableColumn* column = table->Columns.Data;
@ -2378,7 +2378,7 @@ void ImGui::TableSaveSettings(ImGuiTable* table)
column_settings->Visible = column->IsActive; column_settings->Visible = column->IsActive;
// We skip saving some data in the .ini file when they are unnecessary to restore our state // We skip saving some data in the .ini file when they are unnecessary to restore our state
// FIXME-TABLE: We don't have logic to easily compare SortOrder to DefaultSortOrder yet. // FIXME-TABLE: We don't have logic to easily compare SortOrder to DefaultSortOrder yet so it's always saved.
if (column->DisplayOrder != n) if (column->DisplayOrder != n)
settings->SaveFlags |= ImGuiTableFlags_Reorderable; settings->SaveFlags |= ImGuiTableFlags_Reorderable;
if (column_settings->SortOrder != -1) if (column_settings->SortOrder != -1)
@ -2411,10 +2411,9 @@ void ImGui::TableLoadSettings(ImGuiTable* table)
{ {
settings = g.SettingsTables.ptr_from_offset(table->SettingsOffset); settings = g.SettingsTables.ptr_from_offset(table->SettingsOffset);
} }
table->IsSettingsLoaded = true; table->SettingsLoadedFlags = settings->SaveFlags;
settings->SaveFlags = table->Flags;
// Serialize ImGuiTable/ImGuiTableColumn --> ImGuiTableSettings/ImGuiTableColumnSettings // Serialize ImGuiTableSettings/ImGuiTableColumnSettings into ImGuiTable/ImGuiTableColumn
ImGuiTableColumnSettings* column_settings = settings->GetColumnSettings(); ImGuiTableColumnSettings* column_settings = settings->GetColumnSettings();
for (int data_n = 0; data_n < settings->ColumnsCount; data_n++, column_settings++) for (int data_n = 0; data_n < settings->ColumnsCount; data_n++, column_settings++)
{ {