Skip to content

Dock nodes' sizes inconsistent when main docking window issues a main menu bar #9161

@miEsMar

Description

@miEsMar

Version/Branch of Dear ImGui:

Version 1.92, Branch: docking

Back-ends:

imgui_impl_glfw.cpp + imgui_impl_vulkan.cpp

Compiler, OS:

gcc, Ubuntu 22.04 LTS

Full config/build information:

No response

Details:

Got back to work on the GUI of my app, and carefully read docs/related issues.

I managed to understand how to set up a docking space and layout. However, as many others before, I was loosing the main menu bar since the main dock node size was then covering everything.
As you suggested in a previous issue, I borrowed the code from DockSapceOverViewport(), by manually adding a MainMenuBar to the window.
However, this seems to break docking nodes' sizes, which are correct if I remove the main menu bar.

Both horizontal splits are set to 50% ratio, but visually they are not the same. I cannot tell which one is wrong, but definitely not the expected result.

Screenshots/Video:

Image

Minimal, Complete and Verifiable Example code:

#if __gui_enable_docking()
    ImGuiID dockspace_id = ImGui::GetID("DockSpace");

    if (ImGui::DockBuilderGetNode(dockspace_id) == nullptr) {
        ImGui::DockBuilderAddNode(dockspace_id, ImGuiDockNodeFlags_DockSpace);

        ImGui::DockBuilderSetNodeSize(dockspace_id, vp->Size);

        ImGuiID dock_left, dock_right;
        ImGui::DockBuilderSplitNode(dockspace_id, ImGuiDir_Left, 0.30f, &dock_left, &dock_right);

        ImGuiID dock_id_file_browser, dock_id_settings, dock_id_scene, dock_id_console;
        ImGui::DockBuilderSplitNode(dock_left, ImGuiDir_Down, 0.50f, &dock_id_settings,
                                    &dock_id_file_browser);
        ImGui::DockBuilderSplitNode(dock_right, ImGuiDir_Down, 0.50f, &dock_id_console,
                                    &dock_id_scene);

        ImGui::DockBuilderDockWindow("File Browser", dock_id_file_browser);
        ImGui::DockBuilderDockWindow("Settings", dock_id_settings);
        ImGui::DockBuilderDockWindow("Scene", dock_id_scene);
        ImGui::DockBuilderDockWindow("Console", dock_id_console);
        ImGui::DockBuilderFinish(dockspace_id);
    }

    ImGui::SetNextWindowPos(vp->WorkPos);
    ImGui::SetNextWindowSize(vp->WorkSize);
    ImGui::SetNextWindowViewport(vp->ID);

    ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_PassthruCentralNode;

    ImGuiWindowFlags host_window_flags = 0;
    host_window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse |
                         ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove |
                         ImGuiWindowFlags_NoDocking;
    host_window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus |
                         ImGuiWindowFlags_MenuBar;


    if (dockspace_flags & ImGuiDockNodeFlags_PassthruCentralNode)
        host_window_flags |= ImGuiWindowFlags_NoBackground;

    // FIXME-OPT: When using ImGuiDockNodeFlags_KeepAliveOnly with DockSpaceOverViewport() we might
    // be able to spare submitting the window, since DockSpace() with that flag doesn't need a
    // window. We'd only need to compute the default ID accordingly.
    if (dockspace_flags & ImGuiDockNodeFlags_KeepAliveOnly)
        host_window_flags |= ImGuiWindowFlags_NoMouseInputs;

    char label[32];
    ImFormatString(label, IM_ARRAYSIZE(label), "WindowOverViewport_%08X", vp->ID);

    ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
    ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
    ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
    ImGui::Begin(label, NULL, host_window_flags);
    {
        ImGui::PopStyleVar(3);

        if (ImGui::BeginMenuBar()) {
            if (ImGui::BeginMenu("Menu")) {
                ImGui::EndMenu();
            }
            ImGui::EndMenuBar();
        }

        // Submit the dockspace
        if (dockspace_id == 0)
            dockspace_id = ImGui::GetID("DockSpace");
        ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags, nullptr);
    }
    ImGui::End();
#endif

    ImGuiWindowFlags wflags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar |
                              ImGuiWindowFlags_NoScrollWithMouse;

    if (ImGui::Begin("File Browser", NULL, wflags)) {
    }
    ImGui::End();
    if (ImGui::Begin("Settings", NULL, wflags)) {
    }
    ImGui::End();


    if (ImGui::Begin("Scene", NULL, wflags)) {
    }
    ImGui::End();

    if (ImGui::Begin("Console", NULL, wflags)) {
    }
    ImGui::End();

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions