Repository: ocornut/imgui

Issue #2700: Background colour of docked windows
Created: 2019-07-29T10:17:07Z
Version/Branch of Dear ImGui:
Version: 1.72 WIP (17102)
Branch: docking
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_dx11.cpp + imgui_impl_win32.cpp
Compiler: Visual C++ 2017
Operating System: Windows 10
Docked windows currently have the flag ImGuiWindowFlags_ChildWindow added to them automatically, which causes them to use ImGuiCol_ChildBg rather than their normal ImGuiCol_WindowBg. Do you think it would be reasonable to add an exception to GetWindowBgColorIdxFromFlags so that they continue to use ImGuiCol_WindowBg if the window's docked?
We have some windows with background colours that differ from the style's default, and this change makes them inconsistent. To workaround it we would need to also adjust ImGuiCol_ChildBg on every dockable window, and pop it immediately after Begin so that any "real" child windows within them are drawn with the proper ImGuiCol_ChildBg.

ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking;

ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->Pos);
ImGui::SetNextWindowSize(viewport->Size);
ImGui::SetNextWindowViewport(viewport->ID);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove;
window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;

ImGuiDockNodeFlags dockspaceFlags = ImGuiDockNodeFlags_PassthruCentralNode;
if (dockspaceFlags & ImGuiDockNodeFlags_PassthruCentralNode)
	window_flags |= ImGuiWindowFlags_NoBackground;

ImGui::SetNextWindowSize(ImVec2(640, 480), ImGuiCond_Always);
ImGui::Begin("Dock", nullptr, window_flags);
ImGui::PopStyleVar(2);
ImGuiID dockspaceID = ImGui::GetID("DockSpace");
ImGui::DockSpace(dockspaceID, ImVec2(0, 0), dockspaceFlags);
ImGui::End();

ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 0.0f, 0.0f, 1.0f)); // Set window background to red
ImGui::Begin("Red Window");
ImGui::PopStyleColor();
ImGui::End();

Duplicate issue #4101: Docking operation resets the background color of attached sub windows
Created: 2021-05-05T09:45:37Z
Version/Branch of Dear ImGui:
Version: v1.83 WIP
Branch: v1.83 WIP_(docking)_
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_win32.cpp + imgui_impl_dx12.cpp
Compiler: Visual Studio 2017
Operating System: Windows 10
My Issue/Question:
Docking operation change the background color of sub window
Screenshots/Video
[ before docking ]

[while docking ]

[after docking ]

// snippet code to create the sub window & set the background color
const ImU32 color =
root_node_id_ != -1 ? evaluate(graph_, root_node_id_) : IM_COL32(255, 20, 147, 255);
ImGui::PushStyleColor(ImGuiCol_WindowBg, color);
ImGui::Begin("output color");
ImGui::End();
ImGui::PopStyleColor();

Closing comment (2021-05-05T10:29:12Z): Hello,
Closing as duplicate of #2700
See in particular my recent post: #2700 (comment)
I've got an "almost working" version of it but it's not easy to fix the edge cases and they would lead to flickering (no background at all for 1-2 frames) in some cases.
Further comments are best posted in #2700. Thank you!