1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-13 17:27:48 +08:00

Merge pull request #23829 from Joehuu/truncating-text-tooltips

Add tooltips to truncated text
This commit is contained in:
Bartłomiej Dach 2023-06-12 23:43:31 +02:00 committed by GitHub
commit af3fbdbfbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 60 additions and 43 deletions

View File

@ -106,12 +106,11 @@ namespace osu.Game.Beatmaps.Drawables.Cards
{
new Drawable[]
{
new OsuSpriteText
new TruncatingSpriteText
{
Text = new RomanisableString(BeatmapSet.TitleUnicode, BeatmapSet.Title),
Font = OsuFont.Default.With(size: 22.5f, weight: FontWeight.SemiBold),
RelativeSizeAxes = Axes.X,
Truncate = true
},
titleBadgeArea = new FillFlowContainer
{
@ -140,21 +139,19 @@ namespace osu.Game.Beatmaps.Drawables.Cards
{
new[]
{
new OsuSpriteText
new TruncatingSpriteText
{
Text = createArtistText(),
Font = OsuFont.Default.With(size: 17.5f, weight: FontWeight.SemiBold),
RelativeSizeAxes = Axes.X,
Truncate = true
},
Empty()
},
}
},
new OsuSpriteText
new TruncatingSpriteText
{
RelativeSizeAxes = Axes.X,
Truncate = true,
Text = BeatmapSet.Source,
Shadow = false,
Font = OsuFont.GetFont(size: 14, weight: FontWeight.SemiBold),

View File

@ -107,12 +107,11 @@ namespace osu.Game.Beatmaps.Drawables.Cards
{
new Drawable[]
{
new OsuSpriteText
new TruncatingSpriteText
{
Text = new RomanisableString(BeatmapSet.TitleUnicode, BeatmapSet.Title),
Font = OsuFont.Default.With(size: 22.5f, weight: FontWeight.SemiBold),
RelativeSizeAxes = Axes.X,
Truncate = true
},
titleBadgeArea = new FillFlowContainer
{
@ -141,12 +140,11 @@ namespace osu.Game.Beatmaps.Drawables.Cards
{
new[]
{
new OsuSpriteText
new TruncatingSpriteText
{
Text = createArtistText(),
Font = OsuFont.Default.With(size: 17.5f, weight: FontWeight.SemiBold),
RelativeSizeAxes = Axes.X,
Truncate = true
},
Empty()
},

View File

@ -3,12 +3,19 @@
#nullable disable
using System;
using osu.Framework.Graphics.Sprites;
namespace osu.Game.Graphics.Sprites
{
public partial class OsuSpriteText : SpriteText
{
[Obsolete("Use TruncatingSpriteText instead.")]
public new bool Truncate
{
set => throw new InvalidOperationException($"Use {nameof(TruncatingSpriteText)} instead.");
}
public OsuSpriteText()
{
Shadow = true;

View File

@ -0,0 +1,29 @@
// 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 osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
namespace osu.Game.Graphics.Sprites
{
/// <summary>
/// A derived version of <see cref="OsuSpriteText"/> which automatically shows non-truncated text in tooltip when required.
/// </summary>
public sealed partial class TruncatingSpriteText : OsuSpriteText, IHasTooltip
{
/// <summary>
/// Whether a tooltip should be shown with non-truncated text on hover.
/// </summary>
public bool ShowTooltip { get; init; } = true;
public LocalisableString TooltipText => Text;
public override bool HandlePositionalInput => IsTruncated && ShowTooltip;
public TruncatingSpriteText()
{
((SpriteText)this).Truncate = true;
}
}
}

View File

@ -335,12 +335,11 @@ namespace osu.Game.Graphics.UserInterface
{
new Drawable[]
{
Text = new OsuSpriteText
Text = new TruncatingSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.X,
Truncate = true,
},
Icon = new SpriteIcon
{

View File

@ -85,7 +85,7 @@ namespace osu.Game.Overlays.Chat.ChannelList
new Drawable?[]
{
createIcon(),
text = new OsuSpriteText
text = new TruncatingSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
@ -94,7 +94,6 @@ namespace osu.Game.Overlays.Chat.ChannelList
Colour = colourProvider.Light3,
Margin = new MarginPadding { Bottom = 2 },
RelativeSizeAxes = Axes.X,
Truncate = true,
},
createMentionPill(),
close = createCloseButton(),

View File

@ -73,14 +73,13 @@ namespace osu.Game.Overlays.Chat
Width = chatting_text_width,
Masking = true,
Padding = new MarginPadding { Horizontal = padding },
Child = chattingText = new OsuSpriteText
Child = chattingText = new TruncatingSpriteText
{
MaxWidth = chatting_text_width - padding * 2,
Font = OsuFont.Torus.With(size: 20),
Colour = colourProvider.Background1,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Truncate = true,
},
},
searchIconContainer = new Container

View File

@ -83,11 +83,9 @@ namespace osu.Game.Overlays.Chat
Action = openUserProfile;
drawableText = new OsuSpriteText
drawableText = new TruncatingSpriteText
{
Shadow = false,
Truncate = true,
EllipsisString = "…",
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
};

View File

@ -100,17 +100,15 @@ namespace osu.Game.Overlays.Dashboard.Home
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new OsuSpriteText
new TruncatingSpriteText
{
RelativeSizeAxes = Axes.X,
Truncate = true,
Font = OsuFont.GetFont(weight: FontWeight.Regular),
Text = BeatmapSet.Title
},
new OsuSpriteText
new TruncatingSpriteText
{
RelativeSizeAxes = Axes.X,
Truncate = true,
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Regular),
Text = BeatmapSet.Artist
},

View File

@ -123,23 +123,23 @@ namespace osu.Game.Overlays.Mods
Direction = FillDirection.Vertical,
Children = new[]
{
titleText = new OsuSpriteText
titleText = new TruncatingSpriteText
{
Font = OsuFont.TorusAlternate.With(size: 18, weight: FontWeight.SemiBold),
RelativeSizeAxes = Axes.X,
Truncate = true,
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
Margin = new MarginPadding
{
Left = -18 * ShearedOverlayContainer.SHEAR
}
},
ShowTooltip = false, // Tooltip is handled by `IncompatibilityDisplayingModPanel`.
},
descriptionText = new OsuSpriteText
descriptionText = new TruncatingSpriteText
{
Font = OsuFont.Default.With(size: 12),
RelativeSizeAxes = Axes.X,
Truncate = true,
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0)
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
ShowTooltip = false, // Tooltip is handled by `IncompatibilityDisplayingModPanel`.
}
}
}

View File

@ -235,7 +235,7 @@ namespace osu.Game.Screens.Play.HUD
}
}
},
usernameText = new OsuSpriteText
usernameText = new TruncatingSpriteText
{
RelativeSizeAxes = Axes.X,
Width = 0.6f,
@ -244,7 +244,6 @@ namespace osu.Game.Screens.Play.HUD
Colour = Color4.White,
Font = OsuFont.Torus.With(size: 14, weight: FontWeight.SemiBold),
Text = User?.Username ?? string.Empty,
Truncate = true,
Shadow = false,
}
}

View File

@ -101,23 +101,21 @@ namespace osu.Game.Screens.Ranking.Expanded
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new OsuSpriteText
new TruncatingSpriteText
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Text = new RomanisableString(metadata.TitleUnicode, metadata.Title),
Font = OsuFont.Torus.With(size: 20, weight: FontWeight.SemiBold),
MaxWidth = ScorePanel.EXPANDED_WIDTH - padding * 2,
Truncate = true,
},
new OsuSpriteText
new TruncatingSpriteText
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Text = new RomanisableString(metadata.ArtistUnicode, metadata.Artist),
Font = OsuFont.Torus.With(size: 14, weight: FontWeight.SemiBold),
MaxWidth = ScorePanel.EXPANDED_WIDTH - padding * 2,
Truncate = true,
},
new Container
{
@ -156,14 +154,13 @@ namespace osu.Game.Screens.Ranking.Expanded
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new OsuSpriteText
new TruncatingSpriteText
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Text = beatmap.DifficultyName,
Font = OsuFont.Torus.With(size: 16, weight: FontWeight.SemiBold),
MaxWidth = ScorePanel.EXPANDED_WIDTH - padding * 2,
Truncate = true,
},
new OsuTextFlowContainer(s => s.Font = OsuFont.Torus.With(size: 12))
{

View File

@ -233,12 +233,11 @@ namespace osu.Game.Screens.Select
RelativeSizeAxes = Axes.X,
Children = new Drawable[]
{
VersionLabel = new OsuSpriteText
VersionLabel = new TruncatingSpriteText
{
Text = beatmapInfo.DifficultyName,
Font = OsuFont.GetFont(size: 24, italics: true),
RelativeSizeAxes = Axes.X,
Truncate = true,
},
}
},
@ -286,19 +285,17 @@ namespace osu.Game.Screens.Select
RelativeSizeAxes = Axes.X,
Children = new Drawable[]
{
TitleLabel = new OsuSpriteText
TitleLabel = new TruncatingSpriteText
{
Current = { BindTarget = titleBinding },
Font = OsuFont.GetFont(size: 28, italics: true),
RelativeSizeAxes = Axes.X,
Truncate = true,
},
ArtistLabel = new OsuSpriteText
ArtistLabel = new TruncatingSpriteText
{
Current = { BindTarget = artistBinding },
Font = OsuFont.GetFont(size: 17, italics: true),
RelativeSizeAxes = Axes.X,
Truncate = true,
},
MapperContainer = new FillFlowContainer
{