Skip to content

Commit

Permalink
Fix tooltips underflowing left side of screen (#4952)
Browse files Browse the repository at this point in the history
* Fix tooltips underflowing left side of screen

If the tooltip is so large it would clip the right side then it would underflow completely off-screen. This just clamps it instead.

* Better

* rubb
  • Loading branch information
metalgearsloth committed Mar 16, 2024
1 parent 69706b0 commit 75a80b7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ END TEMPLATE-->

### Bugfixes

* Fix tooltips not clamping to the left side of the viewport.
* Fix global audio property not being properly set.

### Other
Expand Down
21 changes: 9 additions & 12 deletions Robust.Client/UserInterface/Tooltips.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Numerics;
using System;
using System.Numerics;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Maths;

Expand Down Expand Up @@ -41,20 +42,16 @@ public static void PositionTooltip(Vector2 screenBounds, Vector2 screenPosition,
tooltip.Measure(Vector2Helpers.Infinity);
var combinedMinSize = tooltip.DesiredSize;

LayoutContainer.SetPosition(tooltip, new Vector2(screenPosition.X, screenPosition.Y - combinedMinSize.Y));
// If it overflows right bounds then just place left on the edge.
var right = MathF.Min(screenPosition.X + combinedMinSize.X, screenBounds.X);

var right = tooltip.Position.X + combinedMinSize.X;
var top = tooltip.Position.Y;
// However, better to clamp the end of the tooltip instead of the start.
var left = MathF.Max(0f, right - combinedMinSize.X);

if (right > screenBounds.X)
{
LayoutContainer.SetPosition(tooltip, new(screenPosition.X - combinedMinSize.X, tooltip.Position.Y));
}
var bottom = MathF.Min(screenPosition.Y, screenBounds.Y);
var top = MathF.Max(0f, bottom - combinedMinSize.Y);

if (top < 0f)
{
LayoutContainer.SetPosition(tooltip, new(tooltip.Position.X, 0f));
}
LayoutContainer.SetPosition(tooltip, new Vector2(left, top));
}
}
}

0 comments on commit 75a80b7

Please sign in to comment.