Add tooltips to move with the mouse cursor.

This commit is contained in:
Chandler Cox
2023-09-24 15:14:28 -05:00
parent 248304a78f
commit 87ef35cd4f

View File

@@ -106,6 +106,7 @@ namespace FlaxEngine.GUI
desc.IsTopmost = true;
desc.IsRegularWindow = false;
desc.HasSizingFrame = false;
desc.ShowAfterFirstPaint = true;
_window = Platform.CreateWindow(ref desc);
if (_window == null)
throw new InvalidOperationException("Failed to create tooltip window.");
@@ -197,6 +198,29 @@ namespace FlaxEngine.GUI
{
// Auto hide if mouse leaves control area
var mousePos = Input.MouseScreenPosition;
// Calculate popup direction
float dpiScale = _showTarget.RootWindow.DpiScale;
var dpiSize = Size * dpiScale;
var locationSS = mousePos;
var monitorBounds = Platform.GetMonitorBounds(locationSS);
var rightBottomMonitorBounds = monitorBounds.BottomRight;
var rightBottomLocationSS = locationSS + dpiSize;
// Prioritize tooltip placement within parent window, fall back to virtual desktop
if (rightBottomMonitorBounds.Y < rightBottomLocationSS.Y)
{
// Direction: up
locationSS.Y -= dpiSize.Y + 10;
}
if (rightBottomMonitorBounds.X < rightBottomLocationSS.X)
{
// Direction: left
locationSS.X -= dpiSize.X + 20;
}
_window.Position = locationSS + new Float2(15, 10);
var location = _showTarget.PointFromScreen(mousePos);
if (!_showTarget.OnTestTooltipOverControl(ref location))
{