mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
MovingWindow: Track click offset based on MovingWindow and not its RootWindow. Followup to 3849bb4470
. Comments + adding a local to ease patch #1345.
This commit is contained in:
parent
8b432cf590
commit
514d30d8cd
15
imgui.cpp
15
imgui.cpp
@ -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
|
||||
@ -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;
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user