Good way to reset internal imgui layout/config?
Version/Branch of Dear ImGui:
1.91.9 WIP - docking
Back-ends:
win32 dx11 / (Linux/EmSDK) sdl2 / opengl3
Compiler, OS:
GCC / MSVC
Full config/build information:
Dear ImGui 1.91.9 WIP (19188)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 4, sizeof(ImDrawVert): 20
define: __cplusplus=202002
define: IMGUI_DISABLE_OBSOLETE_FUNCTIONS
define: __linux__
define: __GNUC__=13
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_sdl2
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000481
NavEnableKeyboard
DockingEnable
ViewportsEnable
io.ConfigViewportsNoAutoMerge
io.ConfigViewportsNoDefaultParent
io.ConfigDockingWithShift
io.ConfigNavCaptureKeyboard
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C0E
HasMouseCursors
HasSetMousePos
PlatformHasViewports
HasMouseHoveredViewport
RendererHasVtxOffset
RendererHasViewports
--------------------------------
io.Fonts: 12 fonts, Flags: 0x00000004, TexSize: 1024,2048
io.DisplaySize: 1.00,1.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00
Details:
I'm trying to clear the internal config in ImGui because I have multiple sets of INI config that I can load and save in real-time.
This all works well for most cases, however I'm not sure what to do in the following scenario:
a) When I have a saved config that does not contain layout for a window X, and I load that config, then ideally, I want that window to revert to FirstUseEver state.
b) Failing that, I can live with it if that the window remains at the size/position it is after loading the config that did not contain metrics for that window. - However, I find that if that window was docked, then it gets undocked (even though the initial state at creation was docked and it weas never undocked).
I've tried using the internal ImGui::ClearIniSettings() call, or ImGui::LoadIniSettingsFromMemory("") but neither work for me.
Is there something else I can try? Or is the desired behavior impossible?
Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
No response
Hello,
I have yet to construct a proper test bed for it, but as an experiment could you try running (after ClearIniSettings()):
ImGuiContext& g = *ImGui::GetCurrentContext();
for (ImGuiWindow* window : g.Windows)
ImGui::ClearWindowSettings(window->Name);
Ideally we would call InitOrLoadWindowSettings() directly:
for (ImGuiWindow* window : g.Windows)
InitOrLoadWindowSettings(window, NULL);
But it is static function inside imgui.cpp (you may try without the static and by declaring it).
And see how far you can get with this? If it works we can decide how to interface it.
Additionally, in case you want to also reset tree node state, you would probably need to do:
for (ImGuiWindow* window : g.Windows)
window->StateStorage.Clear();
This is indeed working.
For now just the window positions and docking makes all the difference. May add the tree nodes later as well.
Also, what about table column specs? (hidden/sizes/orders/sort etc.)?
Anything else?
I'll try to investigate and sort out a design later, but by the way, a perfectly acceptable technique may also be to simply destroy and recreate an imgui context as well. If you can keep the atlas around it should be unnoticeable.