Refactor LoadingButton

This commit is contained in:
Andrei Zavatski
2019-10-24 17:49:34 +03:00
parent 4f79ac8095
commit 85769982a0
3 changed files with 54 additions and 50 deletions

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers;
using osuTK;
@ -11,8 +10,6 @@ namespace osu.Game.Graphics.UserInterface
{
public abstract class LoadingButton : OsuHoverContainer
{
private const float fade_duration = 200;
private bool isLoading;
public bool IsLoading
@ -27,14 +24,12 @@ namespace osu.Game.Graphics.UserInterface
if (value)
{
loading.Show();
text.FadeOut(fade_duration, Easing.OutQuint);
OnLoadingStart();
OnLoadStarted();
}
else
{
loading.Hide();
text.FadeIn(fade_duration, Easing.OutQuint);
OnLoadingFinished();
OnLoadFinished();
}
}
}
@ -46,17 +41,12 @@ namespace osu.Game.Graphics.UserInterface
}
private readonly LoadingAnimation loading;
private readonly Drawable text;
protected LoadingButton()
{
Container content;
Child = content = CreateContent();
content.AddRange(new[]
AddRange(new[]
{
text = CreateText(),
CreateContent(),
loading = new LoadingAnimation
{
Anchor = Anchor.Centre,
@ -82,16 +72,14 @@ namespace osu.Game.Graphics.UserInterface
}
}
protected virtual void OnLoadingStart()
protected virtual void OnLoadStarted()
{
}
protected virtual void OnLoadingFinished()
protected virtual void OnLoadFinished()
{
}
protected abstract Container CreateContent();
protected abstract Drawable CreateText();
protected abstract Drawable CreateContent();
}
}

View File

@ -14,6 +14,8 @@ namespace osu.Game.Graphics.UserInterface
{
public class ShowMoreButton : LoadingButton
{
private const int duration = 200;
private Color4 chevronIconColour;
protected Color4 ChevronIconColour
@ -34,43 +36,50 @@ namespace osu.Game.Graphics.UserInterface
private ChevronIcon rightChevron;
private SpriteText text;
private Box background;
private FillFlowContainer textContainer;
public ShowMoreButton()
{
AutoSizeAxes = Axes.Both;
}
protected override Container CreateContent() => new CircularContainer
protected override Drawable CreateContent() => new CircularContainer
{
Masking = true,
Size = new Vector2(140, 30),
Child = background = new Box
{
RelativeSizeAxes = Axes.Both,
}
};
protected override Drawable CreateText() => new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(7),
Children = new Drawable[]
{
leftChevron = new ChevronIcon(),
text = new OsuSpriteText
background = new Box
{
RelativeSizeAxes = Axes.Both,
},
textContainer = new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
Text = "show more".ToUpper(),
},
rightChevron = new ChevronIcon(),
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(7),
Children = new Drawable[]
{
leftChevron = new ChevronIcon(),
text = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
Text = "show more".ToUpper(),
},
rightChevron = new ChevronIcon(),
}
}
}
};
protected override void OnLoadStarted() => textContainer.FadeOut(duration, Easing.OutQuint);
protected override void OnLoadFinished() => textContainer.FadeIn(duration, Easing.OutQuint);
private class ChevronIcon : SpriteIcon
{
private const int icon_size = 8;