Add tooltips to move with the mouse cursor.
This commit is contained in:
@@ -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))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user