1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 05:42:56 +08:00

Combine hover/active state handling in tab control

This commit is contained in:
smoogipoo 2019-04-26 12:41:00 +09:00
parent d5b91c6455
commit 4adf590036

View File

@ -24,10 +24,10 @@ namespace osu.Game.Overlays.Profile.Header
get => accentColour; get => accentColour;
set set
{ {
if (accentColour == value) return; if (accentColour == value)
return;
accentColour = value; accentColour = value;
bar.Colour = value; bar.Colour = value;
foreach (TabItem<string> tabItem in TabContainer) foreach (TabItem<string> tabItem in TabContainer)
@ -76,10 +76,13 @@ namespace osu.Game.Overlays.Profile.Header
get => accentColour; get => accentColour;
set set
{ {
accentColour = value; if (accentColour == value)
return;
accentColour = value;
bar.Colour = value; bar.Colour = value;
if (!Active.Value) text.Colour = value;
updateState();
} }
} }
@ -112,37 +115,40 @@ namespace osu.Game.Overlays.Profile.Header
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
{ {
if (!Active.Value) base.OnHover(e);
onActivated(true);
return base.OnHover(e); updateState();
return true;
} }
protected override void OnHoverLost(HoverLostEvent e) protected override void OnHoverLost(HoverLostEvent e)
{ {
base.OnHoverLost(e); base.OnHoverLost(e);
if (!Active.Value) updateState();
OnDeactivated();
} }
protected override void OnActivated() protected override void OnActivated() => updateState();
{
onActivated();
}
protected override void OnDeactivated() protected override void OnDeactivated() => updateState();
{
text.FadeColour(AccentColour, 120, Easing.InQuad);
bar.ResizeHeightTo(0, 120, Easing.InQuad);
text.Font = text.Font.With(weight: FontWeight.Medium);
}
private void onActivated(bool fake = false) private void updateState()
{ {
text.FadeColour(Color4.White, 120, Easing.InQuad); if (Active.Value || IsHovered)
bar.ResizeHeightTo(7.5f, 120, Easing.InQuad); {
if (!fake) text.FadeColour(Color4.White, 120, Easing.InQuad);
text.Font = text.Font.With(weight: FontWeight.Bold); bar.ResizeHeightTo(7.5f, 120, Easing.InQuad);
if (Active.Value)
text.Font = text.Font.With(weight: FontWeight.Bold);
}
else
{
text.FadeColour(AccentColour, 120, Easing.InQuad);
bar.ResizeHeightTo(0, 120, Easing.InQuad);
text.Font = text.Font.With(weight: FontWeight.Medium);
}
} }
} }
} }