Skip to content
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

Windows docked on tabview getting undocked on startup and tab change #2720

Closed
KonstantinVeljanovski opened this issue Aug 9, 2019 · 1 comment
Labels

Comments

@KonstantinVeljanovski
Copy link

Version: 1.72b
Branch: docking
Operating System: windows 10

Hello, I am having an issue where the windows refuse to stay docked on startup and when i change tabs.
Here is the setup:
`

        void ShowSceneView(bool *p_open) {
	ImGuiWindowFlags window_flags = ImGuiWindowFlags_None;
	window_flags |=  ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize ;
	window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
	ImGuiViewport* viewport = ImGui::GetMainViewport();
	ImGui::SetNextWindowPos(viewport->Pos);
	ImGui::SetNextWindowSize(viewport->Size);
	ImGui::SetNextWindowViewport(viewport->ID);
	window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove;
	window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
	ImGui::Begin("Test",p_open,window_flags);
	
	if (ImGui::BeginTabBar("Main",ImGuiTabBarFlags_AutoSelectNewTabs | ImGuiTabBarFlags_Reorderable))
	{
		if (ImGui::BeginTabItem("Layout",NULL,ImGuiTabBarFlags_TabListPopupButton))
		{
			
			// Dockspace
			ImGuiIO& io = ImGui::GetIO();
			if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable)
			{
				ImGuiID dockspace_id = ImGui::GetID("Test");
				ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f));
			}
			
			ImGui::EndTabItem();
		}
		if (ImGui::BeginTabItem("Animation", NULL, ImGuiTabBarFlags_TabListPopupButton))
		{

			// Dockspace
			ImGuiIO& io = ImGui::GetIO();
			if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable)
			{
				ImGuiID dockspace_id = ImGui::GetID("Test1");
				ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f));
			}

			ImGui::EndTabItem();
		}
		if (ImGui::BeginTabItem("Shader", NULL, ImGuiTabBarFlags_TabListPopupButton))
		{

			// Dockspace
			ImGuiIO& io = ImGui::GetIO();
			if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable)
			{
				ImGuiID dockspace_id = ImGui::GetID("Test2");
				ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f));
			}

			ImGui::EndTabItem();
		}
		if (ImGui::BeginTabItem("Node Editor", NULL, ImGuiTabBarFlags_TabListPopupButton))
		{

			// Dockspace
			ImGuiIO& io = ImGui::GetIO();
			if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable)
			{
				ImGuiID dockspace_id = ImGui::GetID("Test3");
				ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f));
			}

			ImGui::EndTabItem();
		}
		ImGui::EndTabBar();
	}
	ImGui::End();
}`

I am most likely doing things wrong.
could someone explain a better approach to creating a dock on each tab in tab view?

Thanks for the help!

@ocornut
Copy link
Owner

ocornut commented May 27, 2021

Hello,

Your problem is the same as #2599. If you are not submitting a dockspace, windows docked into it gets undocked.

Your solution here would be to call DockSpace() with the ImGuiDockNodeFlags_KeepAliveOnly flags for all the "hidden" dockspaces to let the system know that they haven't been dropped.

This would probably requires a little bit of refactor of the structure above. I would compute all the dockspace id before the call to BeginTabItem(), record which tab is visible, and then at the end submit all dockspace which haven't been submitted but with the ImGuiDockNodeFlags_KeepAliveOnly flag.

PS: Calling BeginTabItem() with ImGuiTabBarFlags_ values instead of ImGuiTabItemFlags_ values is incorrect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants