Docking: Fix undocking (#3243), amend 7b3d3798 (#1738)

This commit is contained in:
ocornut
2020-05-18 15:08:47 +02:00
parent 3b3af6b731
commit 615e9ae345
2 changed files with 14 additions and 4 deletions

View File

@ -6796,9 +6796,14 @@ void ImGui::FocusWindow(ImGuiWindow* window)
IM_ASSERT(window == NULL || window->RootWindow != NULL);
ImGuiWindow* focus_front_window = window ? window->RootWindowDockStop : NULL;
ImGuiWindow* display_front_window = window ? window->RootWindow : NULL;
ImGuiDockNode* dock_node = window ? window->DockNode : NULL;
bool active_id_window_is_dock_node_host = (g.ActiveIdWindow && dock_node && dock_node->HostWindow == g.ActiveIdWindow);
// Steal focus on active widgets
if (g.ActiveId != 0 && g.ActiveIdWindow && g.ActiveIdWindow->RootWindowDockStop != focus_front_window)
// Steal active widgets. Some of the cases it triggers includes:
// - Focus a window while an InputText in another window is active, if focus happens before the old InputText can run.
// - When using Nav to activate menu items (due to timing of activating on press->new window appears->losing ActiveId)
// - Using dock host items (tab, collapse button) can trigger this before we redirect the ActiveIdWindow toward the child window.
if (g.ActiveId != 0 && g.ActiveIdWindow && g.ActiveIdWindow->RootWindowDockStop != focus_front_window && !active_id_window_is_dock_node_host)
ClearActiveID();
// Passing NULL allow to disable keyboard focus
@ -6807,8 +6812,8 @@ void ImGui::FocusWindow(ImGuiWindow* window)
window->LastFrameJustFocused = g.FrameCount;
// Select in dock node
if (window->DockNode && window->DockNode->TabBar)
window->DockNode->TabBar->SelectedTabId = window->DockNode->TabBar->NextSelectedTabId = window->ID;
if (dock_node && dock_node->TabBar)
dock_node->TabBar->SelectedTabId = dock_node->TabBar->NextSelectedTabId = window->ID;
// Bring to front
BringWindowToFocusFront(focus_front_window);