Reduce transform overhead of `RestoreDefaultValueButton`

This commit is contained in:
Dean Herbert 2021-08-16 18:40:34 +09:00
parent 1c7cbc8621
commit c191b38125
1 changed files with 13 additions and 5 deletions

View File

@ -6,6 +6,7 @@
using osuTK.Graphics;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.UserInterface;
@ -38,7 +39,9 @@ public Bindable<T> Current
current.ValueChanged += _ => UpdateState();
current.DefaultChanged += _ => UpdateState();
current.DisabledChanged += _ => UpdateState();
UpdateState();
if (IsLoaded)
UpdateState();
}
}
@ -81,7 +84,10 @@ private void load(OsuColour colour)
protected override void LoadComplete()
{
base.LoadComplete();
UpdateState();
// avoid unnecessary transforms on first display.
Alpha = currentAlpha;
Colour = currentColour;
}
public LocalisableString TooltipText => "revert to default";
@ -101,14 +107,16 @@ protected override void OnHoverLost(HoverLostEvent e)
public void UpdateState() => Scheduler.AddOnce(updateState);
private float currentAlpha => current.IsDefault ? 0f : hovering && !current.Disabled ? 1f : 0.65f;
private ColourInfo currentColour => current.Disabled ? Color4.Gray : buttonColour;
private void updateState()
{
if (current == null)
return;
this.FadeTo(current.IsDefault ? 0f :
hovering && !current.Disabled ? 1f : 0.65f, 200, Easing.OutQuint);
this.FadeColour(current.Disabled ? Color4.Gray : buttonColour, 200, Easing.OutQuint);
this.FadeTo(currentAlpha, 200, Easing.OutQuint);
this.FadeColour(currentColour, 200, Easing.OutQuint);
}
}
}