Rename button classes to make more sense

This commit is contained in:
Dean Herbert
2022-01-04 17:52:40 +09:00
parent db58f5de8e
commit ee4f5c0e79
6 changed files with 149 additions and 149 deletions

View File

@ -1,88 +1,72 @@
// 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.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics.Sprites;
using osuTK;
using osuTK.Graphics;
using osu.Game.Graphics.Containers;
using osu.Framework.Input.Events;
using JetBrains.Annotations;
namespace osu.Game.Graphics.UserInterface.PageSelector
{
public class PageSelectorButton : PageSelectorItem
public abstract class PageSelectorButton : OsuClickableContainer
{
private readonly string text;
protected const int DURATION = 200;
private Box fadeBox;
private SpriteIcon icon;
private OsuSpriteText name;
[Resolved]
protected OsuColour Colours { get; private set; }
private readonly Anchor alignment;
protected Box Background;
public PageSelectorButton(bool rightAligned, string text)
public CircularContainer CircularContent { get; private set; }
protected PageSelectorButton()
{
this.text = text;
alignment = rightAligned ? Anchor.x0 : Anchor.x2;
AutoSizeAxes = Axes.X;
Height = 20;
}
protected override Drawable CreateContent() => new Container
{
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Children = new Drawable[]
{
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Spacing = new Vector2(3, 0),
Children = new Drawable[]
{
name = new OsuSpriteText
{
Font = OsuFont.GetFont(size: 12),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = text.ToUpper(),
},
icon = new SpriteIcon
{
Icon = alignment == Anchor.x2 ? FontAwesome.Solid.ChevronLeft : FontAwesome.Solid.ChevronRight,
Size = new Vector2(8),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
}
},
}
};
[BackgroundDependencyLoader]
private void load()
{
Background.Colour = Colours.GreySeaFoamDark;
name.Colour = icon.Colour = Colours.Lime;
}
protected override void LoadComplete()
{
base.LoadComplete();
CircularContent.Add(fadeBox = new Box
Add(CircularContent = new CircularContainer
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black.Opacity(100)
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Masking = true,
Children = new[]
{
Background = new Box
{
RelativeSizeAxes = Axes.Both
},
CreateContent().With(content =>
{
content.Anchor = Anchor.Centre;
content.Origin = Anchor.Centre;
content.Margin = new MarginPadding { Horizontal = 10 };
})
}
});
Enabled.BindValueChanged(enabled => fadeBox.FadeTo(enabled.NewValue ? 0 : 1, DURATION), true);
}
protected override void UpdateHoverState() => Background.FadeColour(IsHovered ? Colours.GreySeaFoam : Colours.GreySeaFoamDark, DURATION, Easing.OutQuint);
[NotNull]
protected abstract Drawable CreateContent();
protected override bool OnHover(HoverEvent e)
{
UpdateHoverState();
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
UpdateHoverState();
}
protected abstract void UpdateHoverState();
}
}