imgui: Table Persistence optimization is breaking reloads.
Version/Branch of Dear ImGui:
1.91-docking
Back-ends:
SDL
Compiler, OS:
Linux + GCC
Full config/build information:
No response
Details:
I’m using multiple save / restore config calls including both ImGui window layout and table layout in order to store and retrieve “workspaces”.
This works beautifully, window positions, etc. are restored and table information as well.
I can switch back and forth between config by loading the ini no problem and windows update responsively.
However, I’ve noticed that some tables sometimes seem to lose their column information, and I’ve traced it down to an optimization in imgui_tables.cpp (line 3634 onwards), If I change the code as indicated, my INI is slightly larger, but it all works.
how to reproduce The issue is when a table is created with a default visibility (let’s say hidden), Then that visibility is not stored in the config when the user persists the state. If the config is loaded into a new environment it works, but if the user made those columns visible, then loaded the config that had it hidden, then the columns are not hidden since those INI items were not written.
I expected it to work the same way with window positions that are persisted even though they have not been moved from their default initial location.
The window example is sensible, and I can understand why the optimization for table column state was initially added, but I think removing it may be more robust.
I’m assuming very few other people use config to switch workspaces on the fly like this.
Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
// We skip saving some data in the .ini file when they are unnecessary to restore our state.
// Note that fixed width where initial width was derived from auto-fit will always be saved as InitStretchWeightOrWidth will be 0.0f.
// FIXME-TABLE: We don't have logic to easily compare SortOrder to DefaultSortOrder yet so it's always saved when present.
if (width_or_weight != column->InitStretchWeightOrWidth)
settings->SaveFlags |= ImGuiTableFlags_Resizable;
if (column->DisplayOrder != n)
settings->SaveFlags |= ImGuiTableFlags_Reorderable;
if (column->SortOrder != -1)
settings->SaveFlags |= ImGuiTableFlags_Sortable;
if (column->IsUserEnabled != ((column->Flags & ImGuiTableColumnFlags_DefaultHide) == 0))
settings->SaveFlags |= ImGuiTableFlags_Hideable;
should perhaps just be:
settings->SaveFlags |= ImGuiTableFlags_Resizable;
settings->SaveFlags |= ImGuiTableFlags_Reorderable;
settings->SaveFlags |= ImGuiTableFlags_Sortable;
settings->SaveFlags |= ImGuiTableFlags_Hideable;
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 19 (15 by maintainers)
Commits related to this issue
- Tables: fixed an issue where Columns Visible/Hidden state wouldn't be correctly overridden when hot-reloading .ini state. (#7934) — committed to ocornut/imgui by ocornut 2 years ago
- TestSuite: amend "table_settings_1" to test for an issue restoring Visible/Hidden state with ImGuiTableColumnFlags_DefaultHide. https://github.com/ocornut/imgui/issues/7934 — committed to ocornut/imgui_test_engine by ocornut 2 years ago
- Tables: tamed some .ini settings optimizations to more accurately allow overwriting/hot-reloading settings. (#7934) — committed to ocornut/imgui by ocornut 2 years ago
- TestSuite: added "table_settings_3". https://github.com/ocornut/imgui/issues/7934 — committed to ocornut/imgui_test_engine by ocornut 2 years ago
- Tables: fixed an issue where Columns Width state wouldn't be correctly restored when hot-reloading .ini state. (#7934) Amend 7cd31c355 column->SortDirection initialized setting was wrong in first blo... — committed to ocornut/imgui by ocornut 2 years ago
- Tables: share code between TableSetupColumn() and TableLoadSettings(). (#7934) — committed to ocornut/imgui by ocornut 2 years ago
- Squashed commit of the following: commit 2db3e9d439661194a0e2ace66346ed4e706a5a27 Author: ocornut <omarcornut@gmail.com> Date: Tue Feb 25 17:11:56 2025 +0100 Backends: SDL2, SDL3: Use display ... — committed to LalisaTM/imgui by LalisaTM 2 years ago
- Tables: fixed an issue with TableSetupColumn() overriding ini data. (#7934) Amend 05742f9b6f — committed to ocornut/imgui by ocornut 2 years ago
- Tables: fixed assert/issues loading settings. (#8496, #7934) Not sure what I did with 05742f9b6ff but I missed on the primary filter. — committed to ocornut/imgui by ocornut 2 years ago
This is working for me now, I’ve tried to test all the permutations I could think of.
I’ve tried your commits in our codebase, and it looks like the column visibility persistence is working, but the column size of columns that were not modified breaks on restore.
I did a simple save of settings with a column that had a default fixed width, and immediately restored it. What it seems to do is change the column to best fit or something.
If I modify a column width then that still works (as it had before).
My column (at index 3 as an example) is created with the following lines:
And the ini when saved without any changes contains only:
If I quit and restart the app, then it works, just if I reload the saved config all my unmodified columns seems to revert to “best fit”.
Also, when I resize only column 0 and resave, it changes to:
This (obviously) then works subsequently whatever I do since all the values are explicit.
The code between master and docking looks too dissimilar for me to apply this patch easily.
But as of docking v1.91.9 WIP, when saving a config containing unmodified settings that match the default, then modifying setting, then restoring the original saved setting, does not restore: