Viewports: Improve menu positioning in multi-monitor setups.

This change uses mouse position for initial positioning of popup menus. It ensures that menu appears in expected location on monitor mouse is currently hovering. This change fixes incorrect menu positioning (permanent or on the first frame) when menu item spans multiple monitors.
This commit is contained in:
Rokas Kupstys 2020-02-24 15:14:04 +02:00 committed by ocornut
parent 7d80a8f4f5
commit 3ff13edad9

View File

@ -10986,7 +10986,7 @@ static void ImGui::UpdateSelectWindowViewport(ImGuiWindow* window)
ImVec2 mouse_ref = (flags & ImGuiWindowFlags_Tooltip) ? g.IO.MousePos : g.BeginPopupStack.back().OpenMousePos; ImVec2 mouse_ref = (flags & ImGuiWindowFlags_Tooltip) ? g.IO.MousePos : g.BeginPopupStack.back().OpenMousePos;
bool use_mouse_ref = (g.NavDisableHighlight || !g.NavDisableMouseHover || !g.NavWindow); bool use_mouse_ref = (g.NavDisableHighlight || !g.NavDisableMouseHover || !g.NavWindow);
bool mouse_valid = IsMousePosValid(&mouse_ref); bool mouse_valid = IsMousePosValid(&mouse_ref);
if ((window->Appearing || (flags & ImGuiWindowFlags_Tooltip)) && (!use_mouse_ref || mouse_valid)) if ((window->Appearing || (flags & (ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_ChildMenu))) && (!use_mouse_ref || mouse_valid))
window->ViewportAllowPlatformMonitorExtend = FindPlatformMonitorForPos((use_mouse_ref && mouse_valid) ? mouse_ref : NavCalcPreferredRefPos()); window->ViewportAllowPlatformMonitorExtend = FindPlatformMonitorForPos((use_mouse_ref && mouse_valid) ? mouse_ref : NavCalcPreferredRefPos());
else else
window->ViewportAllowPlatformMonitorExtend = window->Viewport->PlatformMonitor; window->ViewportAllowPlatformMonitorExtend = window->Viewport->PlatformMonitor;