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

Most upvoted comments

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:

    ImGuiTableColumnFlags const colFlag = ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoHeaderWidth | ImGuiTableColumnFlags_NoSort;
    ImGui::TableSetupColumn("Ask", colFlag, w4 * 6);

And the ini when saved without any changes contains only:

[Table][0x2A80B1C9,12]
RefScale=19.5

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:

[Table][0x2A80B1C9,12]
RefScale=19.5
Column 0  Width=154
Column 1  Width=54
Column 2  Width=81
Column 3  Width=54
Column 4  Width=54
Column 5  Width=54
Column 6  Width=27
Column 7  Width=36
Column 8  Width=54
Column 9  Width=36
Column 10 Width=36
Column 11 Width=4096

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:

  • column order
  • column visibility
  • column width
  • current sort