Hide header text when it won't fit in the toolbox group

This commit is contained in:
Dean Herbert 2022-01-06 23:08:50 +09:00
parent 690b425380
commit 5aca2dd4ce
1 changed files with 15 additions and 3 deletions

View File

@ -2,11 +2,13 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Extensions.EnumExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Framework.Layout;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
@ -53,6 +55,8 @@ public bool Expanded
private Color4 expandedColour;
private readonly OsuSpriteText headerText;
/// <summary>
/// Create a new instance.
/// </summary>
@ -90,12 +94,10 @@ protected SettingsToolboxGroup(string title)
Height = header_height,
Children = new Drawable[]
{
new OsuSpriteText
headerText = new OsuSpriteText
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
RelativeSizeAxes = Axes.X,
Truncate = true,
Text = title.ToUpperInvariant(),
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 17),
Padding = new MarginPadding { Left = 10, Right = 30 },
@ -132,6 +134,16 @@ protected SettingsToolboxGroup(string title)
private const float fade_duration = 800;
private const float inactive_alpha = 0.5f;
protected override bool OnInvalidate(Invalidation invalidation, InvalidationSource source)
{
// These toolbox grouped may be contracted to only show icons.
// For now, let's hide the header to avoid text truncation weirdness in such cases.
if (invalidation.HasFlagFast(Invalidation.DrawSize))
headerText.FadeTo(headerText.DrawWidth < DrawWidth ? 1 : 0, 150, Easing.OutQuint);
return base.OnInvalidate(invalidation, source);
}
protected override void LoadComplete()
{
base.LoadComplete();