mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 17:43:05 +08:00
Merge pull request #29210 from normalid-awa/bugfix/visual/long-commet-tooltip-overflow
Limiting the `OsuTooltip` maximum width to prevent overflow
This commit is contained in:
commit
f41bab0eb8
86
osu.Game.Tests/Visual/UserInterface/TestSceneOsuTooltip.cs
Normal file
86
osu.Game.Tests/Visual/UserInterface/TestSceneOsuTooltip.cs
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Cursor;
|
||||||
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Framework.Localisation;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.Cursor;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public partial class TestSceneOsuTooltip : OsuManualInputManagerTestScene
|
||||||
|
{
|
||||||
|
private TestTooltipContainer container = null!;
|
||||||
|
|
||||||
|
private static readonly string[] test_case_tooltip_string =
|
||||||
|
[
|
||||||
|
"Hello!!",
|
||||||
|
string.Concat(Enumerable.Repeat("Hello ", 100)),
|
||||||
|
|
||||||
|
//TODO: o!f issue: https://github.com/ppy/osu-framework/issues/5007
|
||||||
|
//Enable after o!f fixed
|
||||||
|
// $"H{new string('e', 500)}llo",
|
||||||
|
];
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void SetUp() => Schedule(() =>
|
||||||
|
{
|
||||||
|
Child = new Container
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Padding = new MarginPadding(100),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new Box
|
||||||
|
{
|
||||||
|
Colour = Colour4.Red.Opacity(0.5f),
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
},
|
||||||
|
container = new TestTooltipContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Child = new OsuSpriteText
|
||||||
|
{
|
||||||
|
Text = "Hover me!",
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Font = OsuFont.GetFont(size: 50)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
[TestCaseSource(nameof(test_case_tooltip_string))]
|
||||||
|
public void TestTooltipBasic(string text)
|
||||||
|
{
|
||||||
|
AddStep("Set tooltip content", () => container.TooltipText = text);
|
||||||
|
|
||||||
|
AddStep("Move mouse to container", () => InputManager.MoveMouseTo(new Vector2(InputManager.ScreenSpaceDrawQuad.Centre.X, InputManager.ScreenSpaceDrawQuad.Centre.Y)));
|
||||||
|
|
||||||
|
OsuTooltipContainer.OsuTooltip? tooltip = null!;
|
||||||
|
|
||||||
|
AddUntilStep("Wait for the tooltip shown", () =>
|
||||||
|
{
|
||||||
|
tooltip = container.FindClosestParent<OsuTooltipContainer>().ChildrenOfType<OsuTooltipContainer.OsuTooltip>().FirstOrDefault();
|
||||||
|
return tooltip != null && tooltip.Alpha == 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
AddAssert("Check tooltip is under width limit", () => tooltip != null && tooltip.Width <= 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed partial class TestTooltipContainer : Container, IHasTooltip
|
||||||
|
{
|
||||||
|
public LocalisableString TooltipText { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -10,7 +10,7 @@ using osu.Framework.Graphics.Cursor;
|
|||||||
using osu.Framework.Graphics.Effects;
|
using osu.Framework.Graphics.Effects;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
|
||||||
namespace osu.Game.Graphics.Cursor
|
namespace osu.Game.Graphics.Cursor
|
||||||
{
|
{
|
||||||
@ -27,15 +27,20 @@ namespace osu.Game.Graphics.Cursor
|
|||||||
|
|
||||||
public partial class OsuTooltip : Tooltip
|
public partial class OsuTooltip : Tooltip
|
||||||
{
|
{
|
||||||
|
private const float max_width = 500;
|
||||||
|
|
||||||
private readonly Box background;
|
private readonly Box background;
|
||||||
private readonly OsuSpriteText text;
|
private readonly TextFlowContainer text;
|
||||||
private bool instantMovement = true;
|
private bool instantMovement = true;
|
||||||
|
|
||||||
public override void SetContent(LocalisableString contentString)
|
private LocalisableString lastContent;
|
||||||
{
|
|
||||||
if (contentString == text.Text) return;
|
|
||||||
|
|
||||||
text.Text = contentString;
|
public override void SetContent(LocalisableString content)
|
||||||
|
{
|
||||||
|
if (content.Equals(lastContent))
|
||||||
|
return;
|
||||||
|
|
||||||
|
text.Text = content;
|
||||||
|
|
||||||
if (IsPresent)
|
if (IsPresent)
|
||||||
{
|
{
|
||||||
@ -44,6 +49,8 @@ namespace osu.Game.Graphics.Cursor
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
AutoSizeDuration = 0;
|
AutoSizeDuration = 0;
|
||||||
|
|
||||||
|
lastContent = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OsuTooltip()
|
public OsuTooltip()
|
||||||
@ -65,10 +72,14 @@ namespace osu.Game.Graphics.Cursor
|
|||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Alpha = 0.9f,
|
Alpha = 0.9f,
|
||||||
},
|
},
|
||||||
text = new OsuSpriteText
|
text = new TextFlowContainer(f =>
|
||||||
{
|
{
|
||||||
Padding = new MarginPadding(5),
|
f.Font = OsuFont.GetFont(weight: FontWeight.Regular);
|
||||||
Font = OsuFont.GetFont(weight: FontWeight.Regular)
|
})
|
||||||
|
{
|
||||||
|
Margin = new MarginPadding(5),
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
MaximumSize = new Vector2(max_width, float.PositiveInfinity),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user