Skip to content

Commit

Permalink
MovingWindow: Track click offset based on MovingWindow and not its Ro…
Browse files Browse the repository at this point in the history
…otWindow. Followup to 3849bb4. Comments + adding a local to ease patch #1345.
  • Loading branch information
ocornut committed Jan 14, 2018
1 parent 8b432cf commit 514d30d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2392,10 +2392,17 @@ void ImGui::NewFrame()
IM_ASSERT(g.MovingWindow->MoveId == g.MovingWindowMoveId);
if (g.IO.MouseDown[0])
{
// MovingWindow = window we clicked on, could be a child window. We track it to preserve Focus and so that ActiveIdWindow == MovingWindow and ActiveId == MovingWindow->MoveId for consistency.
// actually_moving_window = MovingWindow->RootWindow.
ImGuiWindow* actually_moving_window = g.MovingWindow->RootWindow;
ImVec2 pos = g.IO.MousePos - g.ActiveIdClickOffset;
if (g.MovingWindow->RootWindow->PosFloat.x != pos.x || g.MovingWindow->RootWindow->PosFloat.y != pos.y)
MarkIniSettingsDirty(g.MovingWindow->RootWindow);
g.MovingWindow->RootWindow->PosFloat = pos;
if (actually_moving_window != g.MovingWindow)
pos += actually_moving_window->PosFloat - g.MovingWindow->PosFloat;
if (actually_moving_window->PosFloat.x != pos.x || actually_moving_window->PosFloat.y != pos.y)
{
MarkIniSettingsDirty(actually_moving_window);
actually_moving_window->PosFloat = pos;
}
FocusWindow(g.MovingWindow);
}
else
Expand Down Expand Up @@ -2950,7 +2957,7 @@ void ImGui::EndFrame()
// Set ActiveId even if the _NoMove flag is set, without it dragging away from a window with _NoMove would activate hover on other windows.
FocusWindow(g.HoveredWindow);
SetActiveID(g.HoveredWindow->MoveId, g.HoveredWindow);
g.ActiveIdClickOffset = g.IO.MousePos - g.HoveredRootWindow->Pos;
g.ActiveIdClickOffset = g.IO.MousePos - g.HoveredWindow->Pos;
if (!(g.HoveredWindow->Flags & ImGuiWindowFlags_NoMove) && !(g.HoveredRootWindow->Flags & ImGuiWindowFlags_NoMove))
{
g.MovingWindow = g.HoveredWindow;
Expand Down
2 changes: 1 addition & 1 deletion imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ struct ImGuiContext
bool ActiveIdAllowOverlap; // Active widget allows another widget to steal active id (generally for overlapping widgets, but not always)
ImVec2 ActiveIdClickOffset; // Clicked offset from upper-left corner, if applicable (currently only set by ButtonBehavior)
ImGuiWindow* ActiveIdWindow;
ImGuiWindow* MovingWindow; // Track the child window we clicked on to move a window.
ImGuiWindow* MovingWindow; // Track the window we clicked on (in order to preserve focus). The actually window that is moved is generally MovingWindow->RootWindow.
ImGuiID MovingWindowMoveId; // == MovingWindow->MoveId
ImVector<ImGuiColMod> ColorModifiers; // Stack for PushStyleColor()/PopStyleColor()
ImVector<ImGuiStyleMod> StyleModifiers; // Stack for PushStyleVar()/PopStyleVar()
Expand Down

0 comments on commit 514d30d

Please sign in to comment.