mirror of
https://github.com/ppy/osu.git
synced 2026-06-08 06:23:39 +08:00
1faf022821
This avoids a case where just the symbol is pushed to the next line,
with its left margin making things look ugly.
I would rather have an actual non-breakable space here, which would push
the adjacent word to the next line as well, but to my understanding
`TextFlowContainer` doesn't handle arbitrary drawables in that way.
| Before | After |
|--------|--------|
| <img width="355" height="109" alt="image"
src="https://github.com/user-attachments/assets/8c7b1c4b-b467-4a60-83c3-07a7bdca0de8"
/> | <img width="356" height="115" alt="image"
src="https://github.com/user-attachments/assets/e90e8ae5-24f3-4672-8e05-1a092b1d8a7b"
/> |
87 lines
2.3 KiB
C#
87 lines
2.3 KiB
C#
// 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.Allocation;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Framework.Graphics.Cursor;
|
|
using osu.Framework.Graphics.Sprites;
|
|
using osu.Framework.Localisation;
|
|
using osu.Game.Graphics.Containers;
|
|
using osuTK;
|
|
|
|
namespace osu.Game.Graphics.UserInterfaceV2
|
|
{
|
|
public partial class FormFieldCaption : CompositeDrawable, IHasTooltip
|
|
{
|
|
private OsuTextFlowContainer textFlow = null!;
|
|
|
|
private LocalisableString caption;
|
|
|
|
public LocalisableString Caption
|
|
{
|
|
get => caption;
|
|
set
|
|
{
|
|
caption = value;
|
|
|
|
if (IsLoaded)
|
|
updateDisplay();
|
|
}
|
|
}
|
|
|
|
private LocalisableString tooltipText;
|
|
|
|
public LocalisableString TooltipText
|
|
{
|
|
get => tooltipText;
|
|
set
|
|
{
|
|
tooltipText = value;
|
|
|
|
if (IsLoaded)
|
|
updateDisplay();
|
|
}
|
|
}
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load()
|
|
{
|
|
RelativeSizeAxes = Axes.X;
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
InternalChild = textFlow = new OsuTextFlowContainer(t => t.Font = OsuFont.Style.Caption1)
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
AutoSizeAxes = Axes.Y,
|
|
};
|
|
}
|
|
|
|
protected override void LoadComplete()
|
|
{
|
|
base.LoadComplete();
|
|
updateDisplay();
|
|
}
|
|
|
|
private void updateDisplay()
|
|
{
|
|
textFlow.Text = caption;
|
|
|
|
if (TooltipText != default)
|
|
{
|
|
// Use a space to pad the icon drawable, so that it does not have
|
|
// an awkward left margin if it gets pushed to a new line.
|
|
textFlow.AddText(" ", t => t.Width = 5);
|
|
textFlow.AddArbitraryDrawable(new SpriteIcon
|
|
{
|
|
Anchor = Anchor.BottomLeft,
|
|
Origin = Anchor.BottomLeft,
|
|
Size = new Vector2(10),
|
|
Icon = FontAwesome.Solid.QuestionCircle,
|
|
Y = 1f,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|