From 75a80b7a8aa33f6ca99ab4b636d5b273a3d2bc72 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Sat, 16 Mar 2024 14:45:17 +1100 Subject: [PATCH] Fix tooltips underflowing left side of screen (#4952) * 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 --- RELEASE-NOTES.md | 1 + Robust.Client/UserInterface/Tooltips.cs | 21 +++++++++------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 96268ac3d9a..709e19d4c37 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -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 diff --git a/Robust.Client/UserInterface/Tooltips.cs b/Robust.Client/UserInterface/Tooltips.cs index aac616f5e2e..21b6345a9ec 100644 --- a/Robust.Client/UserInterface/Tooltips.cs +++ b/Robust.Client/UserInterface/Tooltips.cs @@ -1,4 +1,5 @@ -using System.Numerics; +using System; +using System.Numerics; using Robust.Client.UserInterface.Controls; using Robust.Shared.Maths; @@ -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)); } } }