Skip to content

Commit 6a1011c

Browse files
committed
MovingWindow: Proper fix for 651538e attempt, without altering MovingWindow which has side-effects. Clicking on a window with the ImGuiWIndowFlags_NoMove flags takes an ActiveId so we can't hover something else. (ref #1381, #1337)
1 parent b74f24c commit 6a1011c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

imgui.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,10 +2378,10 @@ void ImGui::NewFrame()
23782378
g.FramerateSecPerFrameIdx = (g.FramerateSecPerFrameIdx + 1) % IM_ARRAYSIZE(g.FramerateSecPerFrame);
23792379
g.IO.Framerate = 1.0f / (g.FramerateSecPerFrameAccum / (float)IM_ARRAYSIZE(g.FramerateSecPerFrame));
23802380

2381-
// Handle user moving window with mouse (at the beginning of the frame to avoid input lag or sheering). Only valid for root windows.
2381+
// Handle user moving window with mouse (at the beginning of the frame to avoid input lag or sheering).
23822382
if (g.MovingWindowMoveId && g.MovingWindowMoveId == g.ActiveId)
23832383
{
2384-
KeepAliveID(g.MovingWindowMoveId);
2384+
KeepAliveID(g.ActiveId);
23852385
IM_ASSERT(g.MovingWindow && g.MovingWindow->RootWindow);
23862386
IM_ASSERT(g.MovingWindow->MoveId == g.MovingWindowMoveId);
23872387
if (g.IO.MouseDown[0])
@@ -2401,6 +2401,13 @@ void ImGui::NewFrame()
24012401
}
24022402
else
24032403
{
2404+
// When clicking/dragging from a window that has the _NoMove flag, we still set the ActiveId in order to prevent hovering others.
2405+
if (g.ActiveIdWindow && g.ActiveIdWindow->MoveId == g.ActiveId)
2406+
{
2407+
KeepAliveID(g.ActiveId);
2408+
if (!g.IO.MouseDown[0])
2409+
ClearActiveID();
2410+
}
24042411
g.MovingWindow = NULL;
24052412
g.MovingWindowMoveId = 0;
24062413
}
@@ -2934,13 +2941,14 @@ void ImGui::EndFrame()
29342941
{
29352942
if (g.HoveredRootWindow != NULL)
29362943
{
2944+
// Set ActiveId even if the _NoMove flag is set, without it dragging away from a window with _NoMove would activate hover on other windows.
29372945
FocusWindow(g.HoveredWindow);
2946+
SetActiveID(g.HoveredWindow->MoveId, g.HoveredWindow);
2947+
g.ActiveIdClickOffset = g.IO.MousePos - g.HoveredRootWindow->Pos;
29382948
if (!(g.HoveredWindow->Flags & ImGuiWindowFlags_NoMove) && !(g.HoveredRootWindow->Flags & ImGuiWindowFlags_NoMove))
29392949
{
29402950
g.MovingWindow = g.HoveredWindow;
29412951
g.MovingWindowMoveId = g.MovingWindow->MoveId;
2942-
SetActiveID(g.MovingWindowMoveId, g.HoveredRootWindow);
2943-
g.ActiveIdClickOffset = g.IO.MousePos - g.MovingWindow->RootWindow->Pos;
29442952
}
29452953
}
29462954
else if (g.NavWindow != NULL && GetFrontMostModalRootWindow() == NULL)

0 commit comments

Comments
 (0)