mirror of
https://github.com/ppy/osu.git
synced 2024-09-22 05:27:23 +08:00
Tidy up state management via bindable usage
This commit is contained in:
parent
7794457550
commit
4e6ab1dad3
@ -35,21 +35,20 @@ namespace osu.Game.Overlays.Comments
|
|||||||
|
|
||||||
private class SortTabItem : TabItem<CommentsSortCriteria>
|
private class SortTabItem : TabItem<CommentsSortCriteria>
|
||||||
{
|
{
|
||||||
private readonly TabButton button;
|
|
||||||
|
|
||||||
public SortTabItem(CommentsSortCriteria value)
|
public SortTabItem(CommentsSortCriteria value)
|
||||||
: base(value)
|
: base(value)
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Both;
|
AutoSizeAxes = Axes.Both;
|
||||||
Child = button = new TabButton(value)
|
Child = new TabButton(value) { Active = { BindTarget = Active } };
|
||||||
{
|
|
||||||
Active = { BindTarget = Active }
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnActivated() => button.Activate();
|
protected override void OnActivated()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnDeactivated() => button.Deactivate();
|
protected override void OnDeactivated()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
private class TabButton : HeaderButton
|
private class TabButton : HeaderButton
|
||||||
{
|
{
|
||||||
@ -69,25 +68,33 @@ namespace osu.Game.Overlays.Comments
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Activate()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
ShowBackground();
|
base.LoadComplete();
|
||||||
text.Font = text.Font.With(weight: FontWeight.Bold);
|
|
||||||
text.Colour = colours.BlueLighter;
|
Active.BindValueChanged(active =>
|
||||||
|
{
|
||||||
|
updateBackgroundState();
|
||||||
|
|
||||||
|
text.Font = text.Font.With(weight: active.NewValue ? FontWeight.Bold : FontWeight.Medium);
|
||||||
|
text.Colour = active.NewValue ? colours.BlueLighter : Color4.White;
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Deactivate()
|
protected override bool OnHover(HoverEvent e)
|
||||||
{
|
{
|
||||||
if (!IsHovered)
|
updateBackgroundState();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnHoverLost(HoverLostEvent e) => updateBackgroundState();
|
||||||
|
|
||||||
|
private void updateBackgroundState()
|
||||||
|
{
|
||||||
|
if (Active.Value || IsHovered)
|
||||||
|
ShowBackground();
|
||||||
|
else
|
||||||
HideBackground();
|
HideBackground();
|
||||||
|
|
||||||
text.Font = text.Font.With(weight: FontWeight.Medium);
|
|
||||||
text.Colour = Color4.White;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnHoverLost(HoverLostEvent e)
|
|
||||||
{
|
|
||||||
if (!Active.Value) base.OnHoverLost(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user