From f208fd7ebb55adc0b21c46c3d60309eb47cad95e Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 26 Mar 2019 12:33:58 +0100 Subject: [PATCH] Docking: Fixed crash with ImGuiDockNodeFlags_AutoHideTabBar flag. (#2423, #2109) --- imgui.cpp | 8 ++++---- imgui_demo.cpp | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 8ee79ed4..1abffcc4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -11915,17 +11915,17 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) if (host_window && node->Windows.Size > 0) { DockNodeUpdateTabBar(node, host_window); - if (node->TabBar->SelectedTabId) - node->SelectedTabID = node->TabBar->SelectedTabId; } else { node->WantCloseAll = false; node->WantCloseTabID = 0; node->IsFocused = false; - if (node->Windows.Size > 0) - node->SelectedTabID = node->Windows[0]->ID; } + if (node->TabBar && node->TabBar->SelectedTabId) + node->SelectedTabID = node->TabBar->SelectedTabId; + else if (node->Windows.Size > 0) + node->SelectedTabID = node->Windows[0]->ID; // Draw payload drop target if (host_window && node->IsVisible) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index ca02f0a3..3de9826f 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -4241,8 +4241,8 @@ static void ShowExampleAppCustomRendering(bool* p_open) void ShowExampleAppDockSpace(bool* p_open) { static bool opt_fullscreen_persistant = true; - static ImGuiDockNodeFlags opt_flags = ImGuiDockNodeFlags_None; bool opt_fullscreen = opt_fullscreen_persistant; + static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None; // We are using the ImGuiWindowFlags_NoDocking flag to make the parent window not dockable into, // because it would be confusing to have two docking targets within each others. @@ -4260,7 +4260,7 @@ void ShowExampleAppDockSpace(bool* p_open) } // When using ImGuiDockNodeFlags_PassthruDockspace, DockSpace() will render our background and handle the pass-thru hole, so we ask Begin() to not render a background. - if (opt_flags & ImGuiDockNodeFlags_PassthruDockspace) + if (dockspace_flags & ImGuiDockNodeFlags_PassthruDockspace) window_flags |= ImGuiWindowFlags_NoBackground; ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); @@ -4275,7 +4275,7 @@ void ShowExampleAppDockSpace(bool* p_open) if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable) { ImGuiID dockspace_id = ImGui::GetID("MyDockspace"); - ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), opt_flags); + ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags); } else { @@ -4290,11 +4290,11 @@ void ShowExampleAppDockSpace(bool* p_open) // which we can't undo at the moment without finer window depth/z control. //ImGui::MenuItem("Fullscreen", NULL, &opt_fullscreen_persistant); - if (ImGui::MenuItem("Flag: NoSplit", "", (opt_flags & ImGuiDockNodeFlags_NoSplit) != 0)) opt_flags ^= ImGuiDockNodeFlags_NoSplit; - if (ImGui::MenuItem("Flag: NoDockingInCentralNode", "", (opt_flags & ImGuiDockNodeFlags_NoDockingInCentralNode) != 0)) opt_flags ^= ImGuiDockNodeFlags_NoDockingInCentralNode; - if (ImGui::MenuItem("Flag: NoResize", "", (opt_flags & ImGuiDockNodeFlags_NoResize) != 0)) opt_flags ^= ImGuiDockNodeFlags_NoResize; - if (ImGui::MenuItem("Flag: PassthruDockspace", "", (opt_flags & ImGuiDockNodeFlags_PassthruDockspace) != 0)) opt_flags ^= ImGuiDockNodeFlags_PassthruDockspace; - if (ImGui::MenuItem("Flag: AutoHideTabBar", "", (opt_flags & ImGuiDockNodeFlags_AutoHideTabBar) != 0)) opt_flags ^= ImGuiDockNodeFlags_AutoHideTabBar; + if (ImGui::MenuItem("Flag: NoSplit", "", (dockspace_flags & ImGuiDockNodeFlags_NoSplit) != 0)) dockspace_flags ^= ImGuiDockNodeFlags_NoSplit; + if (ImGui::MenuItem("Flag: NoDockingInCentralNode", "", (dockspace_flags & ImGuiDockNodeFlags_NoDockingInCentralNode) != 0)) dockspace_flags ^= ImGuiDockNodeFlags_NoDockingInCentralNode; + if (ImGui::MenuItem("Flag: NoResize", "", (dockspace_flags & ImGuiDockNodeFlags_NoResize) != 0)) dockspace_flags ^= ImGuiDockNodeFlags_NoResize; + if (ImGui::MenuItem("Flag: PassthruDockspace", "", (dockspace_flags & ImGuiDockNodeFlags_PassthruDockspace) != 0)) dockspace_flags ^= ImGuiDockNodeFlags_PassthruDockspace; + if (ImGui::MenuItem("Flag: AutoHideTabBar", "", (dockspace_flags & ImGuiDockNodeFlags_AutoHideTabBar) != 0)) dockspace_flags ^= ImGuiDockNodeFlags_AutoHideTabBar; ImGui::Separator(); if (ImGui::MenuItem("Close DockSpace", NULL, false, p_open != NULL)) *p_open = false;