MovingWindow auto-cancelled if active id is stolen (instead of ill-defined bahavior + assert in docking).

Followup to 27343ef
This commit is contained in:
ocornut 2022-06-15 14:58:44 +02:00
parent 27343efb0b
commit 08572189f0

View File

@ -3383,11 +3383,21 @@ void ImGui::GcAwakeTransientWindowBuffers(ImGuiWindow* window)
void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window) void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
// While most behaved code would make an effort to not steal active id during window move/drag operations,
// we at least need to be resilient to it. Cancelling the move is rather aggressive and users of 'master' branch
// may prefer the weird ill-defined half working situation ('docking' did assert), so may need to rework that.
if (g.MovingWindow != NULL && g.ActiveId == g.MovingWindow->MoveId)
{
IMGUI_DEBUG_LOG_ACTIVEID("SetActiveID() cancel MovingWindow\n");
g.MovingWindow = NULL;
}
// Set active id
g.ActiveIdIsJustActivated = (g.ActiveId != id); g.ActiveIdIsJustActivated = (g.ActiveId != id);
if (g.ActiveIdIsJustActivated) if (g.ActiveIdIsJustActivated)
{ {
IMGUI_DEBUG_LOG_ACTIVEID("SetActiveID() old:0x%08X (window \"%s\") -> new:0x%08X (window \"%s\")\n", IMGUI_DEBUG_LOG_ACTIVEID("SetActiveID() old:0x%08X (window \"%s\") -> new:0x%08X (window \"%s\")\n", g.ActiveId, g.ActiveIdWindow ? g.ActiveIdWindow->Name : "", id, window ? window->Name : "");
g.ActiveId, g.ActiveIdWindow ? g.ActiveIdWindow->Name : "", id, window ? window->Name : "");
g.ActiveIdTimer = 0.0f; g.ActiveIdTimer = 0.0f;
g.ActiveIdHasBeenPressedBefore = false; g.ActiveIdHasBeenPressedBefore = false;
g.ActiveIdHasBeenEditedBefore = false; g.ActiveIdHasBeenEditedBefore = false;
@ -7388,9 +7398,8 @@ void ImGui::SetKeyboardFocusHere(int offset)
// It makes sense in the vast majority of cases to never interrupt a drag and drop. // It makes sense in the vast majority of cases to never interrupt a drag and drop.
// When we refactor this function into ActivateItem() we may want to make this an option. // When we refactor this function into ActivateItem() we may want to make this an option.
// Note that g.ActiveId being stolen while g.MovingWindow != NULL is currently ill-defined (subtle side-effects on master, assert in docking), // MovingWindow is protected from most user inputs using SetActiveIdUsingNavAndKeys(), but
// so there's another layer we need to fix. Would make sense to automatically drop g.MovingWindow when g.ActiveId is changed. // is also automatically dropped in the event g.ActiveId is stolen.
// MovingWindow is protected from most user inputs using SetActiveIdUsingNavAndKeys() but we may need to enforce a better more encompassing scheme.
if (g.DragDropActive || g.MovingWindow != NULL) if (g.DragDropActive || g.MovingWindow != NULL)
{ {
IMGUI_DEBUG_LOG_ACTIVEID("SetKeyboardFocusHere() ignored while DragDropActive!\n"); IMGUI_DEBUG_LOG_ACTIVEID("SetKeyboardFocusHere() ignored while DragDropActive!\n");