Make moving window prevent its active id from being stolen (#3392, #3243, #1738)

Amend 7b3d379, 615e9ae3
This commit is contained in:
omar 2020-08-10 16:28:46 +02:00
parent dbc70f21a9
commit a5ba26806f
3 changed files with 9 additions and 4 deletions

View File

@ -2979,6 +2979,7 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window)
} }
g.ActiveId = id; g.ActiveId = id;
g.ActiveIdAllowOverlap = false; g.ActiveIdAllowOverlap = false;
g.ActiveIdNoClearOnFocusLoss = false;
g.ActiveIdWindow = window; g.ActiveIdWindow = window;
g.ActiveIdHasBeenEditedThisFrame = false; g.ActiveIdHasBeenEditedThisFrame = false;
if (id) if (id)
@ -2996,7 +2997,7 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window)
void ImGui::ClearActiveID() void ImGui::ClearActiveID()
{ {
SetActiveID(0, NULL); SetActiveID(0, NULL); // g.ActiveId = 0;
} }
void ImGui::SetHoveredID(ImGuiID id) void ImGui::SetHoveredID(ImGuiID id)
@ -3401,6 +3402,7 @@ void ImGui::StartMouseMovingWindow(ImGuiWindow* window)
FocusWindow(window); FocusWindow(window);
SetActiveID(window->MoveId, window); SetActiveID(window->MoveId, window);
g.NavDisableHighlight = true; g.NavDisableHighlight = true;
g.ActiveIdNoClearOnFocusLoss = true;
g.ActiveIdClickOffset = g.IO.MousePos - window->RootWindow->Pos; g.ActiveIdClickOffset = g.IO.MousePos - window->RootWindow->Pos;
bool can_move_window = true; bool can_move_window = true;
@ -6775,8 +6777,9 @@ void ImGui::FocusWindow(ImGuiWindow* window)
// - Focus a window while an InputText in another window is active, if focus happens before the old InputText can run. // - 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) // - 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. // - 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) if (g.ActiveId != 0 && g.ActiveIdWindow && g.ActiveIdWindow->RootWindowDockStop != focus_front_window)
ClearActiveID(); if (!g.ActiveIdNoClearOnFocusLoss && !active_id_window_is_dock_node_host)
ClearActiveID();
// Passing NULL allow to disable keyboard focus // Passing NULL allow to disable keyboard focus
if (!window) if (!window)

View File

@ -1314,6 +1314,7 @@ struct ImGuiContext
float ActiveIdTimer; float ActiveIdTimer;
bool ActiveIdIsJustActivated; // Set at the time of activation for one frame bool ActiveIdIsJustActivated; // Set at the time of activation for one frame
bool ActiveIdAllowOverlap; // Active widget allows another widget to steal active id (generally for overlapping widgets, but not always) bool ActiveIdAllowOverlap; // Active widget allows another widget to steal active id (generally for overlapping widgets, but not always)
bool ActiveIdNoClearOnFocusLoss; // Disable losing active id if the active id window gets unfocused.
bool ActiveIdHasBeenPressedBefore; // Track whether the active id led to a press (this is to allow changing between PressOnClick and PressOnRelease without pressing twice). Used by range_select branch. bool ActiveIdHasBeenPressedBefore; // Track whether the active id led to a press (this is to allow changing between PressOnClick and PressOnRelease without pressing twice). Used by range_select branch.
bool ActiveIdHasBeenEditedBefore; // Was the value associated to the widget Edited over the course of the Active state. bool ActiveIdHasBeenEditedBefore; // Was the value associated to the widget Edited over the course of the Active state.
bool ActiveIdHasBeenEditedThisFrame; bool ActiveIdHasBeenEditedThisFrame;

View File

@ -7395,8 +7395,9 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
// Undock // Undock
DockContextQueueUndockWindow(&g, docked_window); DockContextQueueUndockWindow(&g, docked_window);
g.MovingWindow = docked_window; g.MovingWindow = docked_window;
g.ActiveId = g.MovingWindow->MoveId; SetActiveID(g.MovingWindow->MoveId, g.MovingWindow);
g.ActiveIdClickOffset -= g.MovingWindow->Pos - bb.Min; g.ActiveIdClickOffset -= g.MovingWindow->Pos - bb.Min;
g.ActiveIdNoClearOnFocusLoss = true;
} }
} }
} }