Misc: Stop moving window if mouse position becomes invalid. Flagged menus are _NoMove for sanity.

This commit is contained in:
omar 2018-04-25 17:55:26 +02:00
parent d317d90610
commit 711a63befc

View File

@ -3272,13 +3272,13 @@ static void ImGui::UpdateMovingWindow()
KeepAliveID(g.ActiveId); KeepAliveID(g.ActiveId);
IM_ASSERT(g.MovingWindow && g.MovingWindow->RootWindow); IM_ASSERT(g.MovingWindow && g.MovingWindow->RootWindow);
ImGuiWindow* moving_window = g.MovingWindow->RootWindow; ImGuiWindow* moving_window = g.MovingWindow->RootWindow;
if (g.IO.MouseDown[0]) if (g.IO.MouseDown[0] && IsMousePosValid(&g.IO.MousePos))
{ {
ImVec2 pos = g.IO.MousePos - g.ActiveIdClickOffset; ImVec2 pos = g.IO.MousePos - g.ActiveIdClickOffset;
if (moving_window->Pos.x != pos.x || moving_window->Pos.y != pos.y) if (moving_window->Pos.x != pos.x || moving_window->Pos.y != pos.y)
{ {
MarkIniSettingsDirty(moving_window); MarkIniSettingsDirty(moving_window);
moving_window->Pos = pos; SetWindowPos(moving_window, pos, ImGuiCond_Always);
} }
FocusWindow(g.MovingWindow); FocusWindow(g.MovingWindow);
} }
@ -11381,7 +11381,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled)
{ {
// Sub-menus are ChildWindow so that mouse can be hovering across them (otherwise top-most popup menu would steal focus and not allow hovering on parent menu) // Sub-menus are ChildWindow so that mouse can be hovering across them (otherwise top-most popup menu would steal focus and not allow hovering on parent menu)
SetNextWindowPos(popup_pos, ImGuiCond_Always); SetNextWindowPos(popup_pos, ImGuiCond_Always);
ImGuiWindowFlags flags = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings | ((window->Flags & (ImGuiWindowFlags_Popup|ImGuiWindowFlags_ChildMenu)) ? ImGuiWindowFlags_ChildMenu|ImGuiWindowFlags_ChildWindow : ImGuiWindowFlags_ChildMenu); ImGuiWindowFlags flags = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings | ((window->Flags & (ImGuiWindowFlags_Popup|ImGuiWindowFlags_ChildMenu)) ? ImGuiWindowFlags_ChildMenu|ImGuiWindowFlags_ChildWindow : ImGuiWindowFlags_ChildMenu);
menu_is_open = BeginPopupEx(id, flags); // menu_is_open can be 'false' when the popup is completely clipped (e.g. zero size display) menu_is_open = BeginPopupEx(id, flags); // menu_is_open can be 'false' when the popup is completely clipped (e.g. zero size display)
} }