From 2f9bae140b8b770804053668d1a0814ce5c4fb11 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 16 Jan 2019 14:43:27 +0100 Subject: [PATCH] Docking: Demo: Fixed docking document window into parent window. (#2286) --- imgui_demo.cpp | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 5f731361..66528bc6 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -4205,24 +4205,32 @@ void ShowExampleAppDocuments(bool* p_open) { static ExampleAppDocuments app; - if (!ImGui::Begin("Example: Documents", p_open, ImGuiWindowFlags_MenuBar)) - { - ImGui::End(); - return; - } - // Options enum Target { Target_None, - Target_Tab, // Create document as a local tab into a local tab bar - Target_Window // Create document as a regular window + Target_Tab, // Create documents as local tab into a local tab bar + Target_DockspaceAndWindow // Create documents as regular windows, and create an embedded dockspace }; static Target opt_target = Target_Tab; static bool opt_reorderable = true; static ImGuiTabBarFlags opt_fitting_flags = ImGuiTabBarFlags_FittingPolicyDefault_; - // Menu + // When (opt_target == Target_DockspaceAndWindow) there is the possibily that one of our child Document window (e.g. "Eggplant") + // that we emit gets docked into the same spot as the parent window ("Example: Documents"). + // This would create a problematic feedback loop because selecting the "Eggplant" tab would make the "Example: Documents" tab + // not visible, which in turn would stop submitting the "Eggplant" window. + // We avoid this problem by submitting our documents window even if our parent window is not currently visible. + // Another solution may be to make the "Example: Documents" window use the ImGuiWindowFlags_NoDocking. + + bool window_contents_visible = ImGui::Begin("Example: Documents", p_open, ImGuiWindowFlags_MenuBar); + if (!window_contents_visible && opt_target != Target_DockspaceAndWindow) + { + ImGui::End(); + return; + } + + // Menu Bar if (ImGui::BeginMenuBar()) { if (ImGui::BeginMenu("File")) @@ -4267,8 +4275,8 @@ void ShowExampleAppDocuments(bool* p_open) ImGui::Combo("Output", (int*)&opt_target, "None\0TabBar+Tabs\0DockSpace+Window\0"); ImGui::PopItemWidth(); bool redock_all = false; - if (opt_target == Target_Tab) { ImGui::SameLine(); ImGui::Checkbox("Reorderable Tabs", &opt_reorderable); } - if (opt_target == Target_Window) { ImGui::SameLine(); redock_all = ImGui::Button("Redock all"); } + if (opt_target == Target_Tab) { ImGui::SameLine(); ImGui::Checkbox("Reorderable Tabs", &opt_reorderable); } + if (opt_target == Target_DockspaceAndWindow) { ImGui::SameLine(); redock_all = ImGui::Button("Redock all"); } ImGui::Separator(); @@ -4313,7 +4321,7 @@ void ShowExampleAppDocuments(bool* p_open) ImGui::EndTabBar(); } } - else if (opt_target == Target_Window) + else if (opt_target == Target_DockspaceAndWindow) { if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_DockingEnable) { @@ -4357,6 +4365,13 @@ void ShowExampleAppDocuments(bool* p_open) } } + // Early out other contents + if (!window_contents_visible) + { + ImGui::End(); + return; + } + // Update closing queue static ImVector close_queue; if (close_queue.empty())