Imgui Docking feature "undocks" previously docked windows
OneAbowAll opened this issue · 2 comments
Summary
For some reason when closing and reopening the app Imgui undocks all the windows that were docked.
Steps to reproduce
- Platform: Desktop
- Framework Version: .NET Core 3, .NET 8
- API: OpenGL
- API Version: OpenGL 4.6 Core
- Dock windows anyway you like
- Close app
- Reopen app
Comments
Right now this is the flags that I'm setting OnLoad:
io.ConfigFlags |= ImGuiConfigFlags.DockingEnable;
And this is the code im using to create the Dockspace / OnRender code:
Gl.Clear((uint) ClearBufferMask.ColorBufferBit);
controller.Update((float)delta);
ImGui.DockSpaceOverViewport(ImGui.GetMainViewport(), ImGuiDockNodeFlags.PassthruCentralNode);
ImGui.BeginDemoWindow();
//etc... etc...
controller.Render();
Example Image
After closing and then reopening the app:

As you can see the window's positions are correct, but the expected behaviour is not.
Ok after looking into it i think i found a solution.
You have to set the DockingEnable config flag as soon as possible inside the constructor of ImGuiController.
public ImGuiController(GL gl, IView view, IInputContext input, ImGuiFontConfig? imGuiFontConfig = null, Action onConfigureIO = null)
{
Init(gl, view, input);
ImGuiIOPtr iO = ImGuiNET.ImGui.GetIO();
if (imGuiFontConfig.HasValue)
{
IntPtr glyph_ranges = imGuiFontConfig.Value.GetGlyphRange?.Invoke(iO) ?? ((IntPtr)0);
iO.Fonts.AddFontFromFileTTF(imGuiFontConfig.Value.FontPath, imGuiFontConfig.Value.FontSize, null, glyph_ranges);
}
onConfigureIO?.Invoke();
iO.BackendFlags |= ImGuiBackendFlags.RendererHasVtxOffset;
iO.ConfigFlags |= ImGuiConfigFlags.DockingEnable;
CreateDeviceResources();
SetKeyMappings();
SetPerFrameImGuiData(1f / 60f);
BeginFrame();
}
I think the problem might be that BeginFrame is called inside the constructor, meaning that any user-specified flag outside the constructor are not considered when drawing the interface for the first time, but its just an educated guess.
I’m glad you found a solution! Note that these sorts of things is why we expose the onConfigureIO callback, so hopefully this helps and you don’t need to manually edit the controller source :)
