From f6ca4b233913916d4ca19a7efee3b61345b90172 Mon Sep 17 00:00:00 2001
From: jkh675 <rluo2018@gmail.com>
Date: Fri, 2 Aug 2024 12:16:50 +0800
Subject: [PATCH] Replace the `OsuSpriteText` with `TextFlowContainer` in
 `OsuTooltip` and limit the max width

---
 .../Graphics/Cursor/OsuTooltipContainer.cs    | 25 ++++++++++++++-----
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/osu.Game/Graphics/Cursor/OsuTooltipContainer.cs b/osu.Game/Graphics/Cursor/OsuTooltipContainer.cs
index aab5b3ee36..cc95a5bd2b 100644
--- a/osu.Game/Graphics/Cursor/OsuTooltipContainer.cs
+++ b/osu.Game/Graphics/Cursor/OsuTooltipContainer.cs
@@ -10,7 +10,7 @@ using osu.Framework.Graphics.Cursor;
 using osu.Framework.Graphics.Effects;
 using osu.Framework.Graphics.Shapes;
 using osu.Framework.Localisation;
-using osu.Game.Graphics.Sprites;
+using osu.Framework.Graphics.Containers;
 
 namespace osu.Game.Graphics.Cursor
 {
@@ -27,13 +27,18 @@ namespace osu.Game.Graphics.Cursor
 
         public partial class OsuTooltip : Tooltip
         {
+            private const float max_width = 1024;
+
             private readonly Box background;
-            private readonly OsuSpriteText text;
+            private readonly TextFlowContainer text;
             private bool instantMovement = true;
 
+            private LocalisableString lastPresent;
+
             public override void SetContent(LocalisableString contentString)
             {
-                if (contentString == text.Text) return;
+                if (contentString.Equals(lastPresent))
+                    return;
 
                 text.Text = contentString;
 
@@ -44,6 +49,8 @@ namespace osu.Game.Graphics.Cursor
                 }
                 else
                     AutoSizeDuration = 0;
+
+                lastPresent = contentString;
             }
 
             public OsuTooltip()
@@ -65,10 +72,16 @@ namespace osu.Game.Graphics.Cursor
                         RelativeSizeAxes = Axes.Both,
                         Alpha = 0.9f,
                     },
-                    text = new OsuSpriteText
+                    text = new TextFlowContainer(f =>
                     {
-                        Padding = new MarginPadding(5),
-                        Font = OsuFont.GetFont(weight: FontWeight.Regular)
+                        f.Font = OsuFont.GetFont(weight: FontWeight.Regular);
+                        f.Truncate = true;
+                        f.MaxWidth = max_width;
+                    })
+                    {
+                        Margin = new MarginPadding(5),
+                        AutoSizeAxes = Axes.Both,
+                        MaximumSize = new Vector2(max_width, float.PositiveInfinity),
                     }
                 };
             }