Fix tooltips to be constrained by monitor bounds instead of virtual desktop or parent window bounds

#470 #540
This commit is contained in:
Wojtek Figat
2021-06-01 12:14:04 +02:00
parent 8a942922fe
commit c5405183c9

View File

@@ -72,19 +72,17 @@ namespace FlaxEngine.GUI
Vector2 dpiSize = Size * dpiScale;
Vector2 locationWS = target.PointToWindow(location);
Vector2 locationSS = parentWin.PointToScreen(locationWS);
Vector2 screenSize = Platform.VirtualDesktopSize;
Vector2 parentWinLocationSS = parentWin.PointToScreen(Vector2.Zero);
float parentWinRightSS = parentWinLocationSS.Y + parentWin.Size.Y;
float parentWinBottomSS = parentWinLocationSS.X + parentWin.Size.X;
Rectangle monitorBounds = Platform.GetMonitorBounds(locationSS);
Vector2 rightBottomMonitorBounds = monitorBounds.BottomRight;
Vector2 rightBottomLocationSS = locationSS + dpiSize;
// Prioritize tooltip placement within parent window, fall back to virtual desktop
if (parentWinRightSS < rightBottomLocationSS.Y || screenSize.Y < rightBottomLocationSS.Y)
if (rightBottomMonitorBounds.Y < rightBottomLocationSS.Y)
{
// Direction: up
locationSS.Y -= dpiSize.Y;
}
if (parentWinBottomSS < rightBottomLocationSS.X || screenSize.X < rightBottomLocationSS.X)
if (rightBottomMonitorBounds.X < rightBottomLocationSS.X)
{
// Direction: left
locationSS.X -= dpiSize.X;