#9212·imgui

How to create a dockspace where 4 retain the same vertical and horizontal divider?

Author: Avelina9XCreated Jan 31, 2026Updated Sep 19, 2026
Labelslayoutdocking

Version/Branch of Dear ImGui:

Version 1.92.5, Branch: docking

Back-ends:

imgui_impl_win32.cpp + imgui_impl_dx11.cpp

Compiler, OS:

Windows 10 MSVC

Full config/build information:

No response

Details:

I need to create 4 quadrants which remain aligned perfectly when moving a horizontal or vertical divider, but I cannot seem to make anything work. Attempting to get use FindWindowByID and then reading the size of one window and writing to the other yields nothing. Using DockBuilder helpers don't because the IDs don't exist after the first frame, and if we try to recreate them every frame it resets back to 50% sizing and then causes a stack overflow.

I'm losing my mind here. I don't think I understand the dockspace system at all.

Screenshots/Video:

How it looks at initialization:

Image

How it looks after moving a horizontal divider:

Image

How it looks after being perfectly aligned in fullscreen, then changing window size:

Image

Minimal, Complete and Verifiable Example code:

cpp
{
	// Create fullscreen dockspace
	ImGuiDockNodeFlags dockspaceFlags = ImGuiDockNodeFlags_None;
	dockspaceFlags |= ImGuiDockNodeFlags_NoUndocking;

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

	const ImGuiViewport* viewport = ImGui::GetMainViewport();
	ImGui::SetNextWindowPos( viewport->WorkPos );
	ImGui::SetNextWindowSize( viewport->WorkSize );
	ImGui::SetNextWindowViewport( viewport->ID );

	ImGui::PushStyleVar( ImGuiStyleVar_WindowRounding, 0.0f );
	ImGui::PushStyleVar( ImGuiStyleVar_WindowBorderSize, 0.0f );
	ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 0.0f, 0.0f ) );

	ImGui::Begin( "MainWindow", nullptr, windowFlags );

	ImGui::PopStyleVar( 3 );

	ImGuiID mainWindowDockspaceID = ImGui::GetID( "MainWindowDockspace" );
	ImGui::DockSpace( mainWindowDockspaceID, ImVec2( 0.0f, 0.0f ), dockspaceFlags );

	{
		// Build menu bar
		if ( ImGui::BeginMenuBar() ) {
			if ( ImGui::BeginMenu( "Options" ) ) {

				ImGui::EndMenu();
			}

			ImGui::EndMenuBar();
		}

		// Create quadrants
		static bool initQuadrants = true;
		if ( initQuadrants ) {
			initQuadrants = false;

			ImGuiID node_top;
			ImGuiID node_bottom;
			ImGui::DockBuilderSplitNode( mainWindowDockspaceID, ImGuiDir_Up, 0.5f, &node_top, &node_bottom );

			ImGuiID node_top_left;
			ImGuiID node_top_right;
			ImGui::DockBuilderSplitNode( node_top, ImGuiDir_Left, 0.5f, &node_top_left, &node_top_right );

			ImGuiID node_bottom_left;
			ImGuiID node_bottom_right;
			ImGui::DockBuilderSplitNode( node_bottom, ImGuiDir_Left, 0.5f, &node_bottom_left, &node_bottom_right );

			ImGui::DockBuilderDockWindow( "PerspectiveViewport", node_top_left );
			ImGui::DockBuilderDockWindow( "TopViewport", node_top_right );
			ImGui::DockBuilderDockWindow( "FrontViewport", node_bottom_left );
			ImGui::DockBuilderDockWindow( "SideViewport", node_bottom_right );
		}
	}

	ImGui::End();

	ImGuiID perspectiveViewportID;
	ImGuiID topViewportID;
	ImGuiID frontViewportID;
	ImGuiID sideViewportID;

	ImGui::Begin( "PerspectiveViewport", nullptr, ImGuiWindowFlags_NoBackground );
	perspectiveViewportID = ImGui::GetCurrentWindow()->ID;
	ImGui::End();

	ImGui::Begin( "TopViewport", nullptr, ImGuiWindowFlags_NoBackground );
	topViewportID = ImGui::GetCurrentWindow()->ID;
	ImGui::End();

	ImGui::Begin( "FrontViewport", nullptr, ImGuiWindowFlags_NoBackground );
	frontViewportID = ImGui::GetCurrentWindow()->ID;
	ImGui::End();

	ImGui::Begin( "SideViewport", nullptr, ImGuiWindowFlags_NoBackground );
	sideViewportID = ImGui::GetCurrentWindow()->ID;
	ImGui::End();

	ImGui::SetWindowSize( "FrontViewport", { ImGui::FindWindowByID( perspectiveViewportID )->Size.x, ImGui::FindWindowByID( frontViewportID )->Size.y } );
}