Skip to content

Allow Splitting same node multiple times #8472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

MegaMech
Copy link

@MegaMech MegaMech commented Mar 7, 2025

This allows splitting a dock node so that you can create a left/right/up/down docking location programmatically.

Without this, the programmer can only split one direction off of the main dockId which prevents docking multiple windows to the other sides of the main program window.

According to other issues regarding docking, this appears to be intended functionality.

Example:

    const ImGuiID dockId = ImGui::GetID("main_dock");
    if (!ImGui::DockBuilderGetNode(dockId)) {
        ImGui::DockBuilderRemoveNode(dockId);
        ImGui::DockBuilderAddNode(dockId, ImGuiDockNodeFlags_NoTabBar);

        ImGui::DockBuilderDockWindow("Main Game", dockId);

        ImGuiID rightId = ImGui::DockBuilderSplitNode(dockId, ImGuiDir_Right, 0.25f, nullptr, nullptr);
        ImGuiID topId = ImGui::DockBuilderSplitNode(dockId, ImGuiDir_Up, 0.25f, nullptr, nullptr);
        ImGuiID bottomId = ImGui::DockBuilderSplitNode(dockId, ImGuiDir_Down, 0.25f, nullptr, nullptr);
        ImGui::DockBuilderSetNodeSize(rightId, ImVec2(viewport->Size.x * 0.2f, viewport->Size.y));
        ImGui::DockBuilderSetNodeSize(topId, ImVec2(viewport->Size.x, viewport->Size.y * 0.1f));
        ImGui::DockBuilderSetNodeSize(bottomId, ImVec2(viewport->Size.x, viewport->Size.y * 0.1f));
        
        ImGui::DockBuilderDockWindow("Scene Explorer", rightId);
        ImGui::DockBuilderDockWindow("Tools", topId);
        ImGui::DockBuilderDockWindow("Content Browser", bottomId);

        ImGui::DockBuilderFinish(dockId);
    }

    ImGui::DockSpace(dockId, ImVec2(0.0f, 0.0f), ImGuiDockNodeFlags_None | ImGuiDockNodeFlags_NoDockingInCentralNode);

@ocornut
Copy link
Owner

ocornut commented Mar 10, 2025

Thank you for the PR and the code snippet (which is very useful).

Before all, you'll want to call ImGui::DockBuilderSetNodeSize(dockId, ImVec2(viewport->Size.x, viewport->Size.y)); right after creating it if you want the subsequent split to correctly reflect given ratios.

It's a little confusing and hard to comprehend even for me as those API haven't been touched for a long time and are not ideal, but what you are doing was not possible at the time I published docking. Effectively now it does, probably because the underlying DockNodeTreeSplit() handles moving things better. I agree it can make use of DockBuilder API a little easier as effectively the building code doesn't have to maintain as many identifiers.

FYI the intent was to build the hierarchy:

ImGuiID topBottomId;
ImGuiID topId = ImGui::DockBuilderSplitNode(dockId, ImGuiDir_Up, 0.25f, nullptr, &topBottomId);

ImGuiID bottomId;
ImGuiID midId;
ImGui::DockBuilderSplitNode(topBottomId, ImGuiDir_Down, 0.25f, &bottomId, &midId);

ImGuiID leftId;
ImGuiID rightId;
ImGui::DockBuilderSplitNode(midId, ImGuiDir_Right, 0.25f, &rightId, &leftId);

ImGui::DockBuilderDockWindow("Main Game", leftId);
ImGui::DockBuilderDockWindow("Scene Explorer", rightId);
ImGui::DockBuilderDockWindow("Tools", topId);
ImGui::DockBuilderDockWindow("Content Browser", bottomId);

Notice how the splits are done in the opposite order, and it is also more verbose and more confusing.

I would need to study the code a little more to confirm that this isn't losing state.

@ocornut ocornut changed the title Allow Splitting dockId multiple times Allow Splitting same node multiple times Mar 10, 2025
ocornut pushed a commit that referenced this pull request Mar 10, 2025
@ocornut
Copy link
Owner

ocornut commented Mar 10, 2025

Merged as bb8d295, thank you.

@ocornut ocornut closed this Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants