Refactor OsuTabControl.AccentColour

This commit is contained in:
Andrei Zavatski 2020-01-24 10:31:47 +03:00
parent 34ffbcf2ae
commit 738980e3f7
2 changed files with 15 additions and 21 deletions

View File

@ -22,12 +22,20 @@ namespace osu.Game.Graphics.UserInterface
{
public class OsuTabControl<T> : TabControl<T>
{
private readonly Bindable<Color4> accentColour = new Bindable<Color4>();
protected readonly Bindable<Color4> AccentColourBindable = new Bindable<Color4>();
public Color4 AccentColour
{
get => accentColour.Value;
set => accentColour.Value = value;
get => AccentColourBindable.Value;
set
{
AccentColourBindable.Value = value;
if (Dropdown is IHasAccentColour dropdown)
dropdown.AccentColour = value;
foreach (var i in TabContainer.Children.OfType<IHasAccentColour>())
i.AccentColour = value;
}
}
private readonly Box strip;
@ -67,24 +75,10 @@ public OsuTabControl()
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
if (accentColour.Value == default)
if (AccentColour == default)
AccentColour = colours.Blue;
}
protected override void LoadComplete()
{
base.LoadComplete();
accentColour.BindValueChanged(OnAccentColourChanged, true);
}
protected virtual void OnAccentColourChanged(ValueChangedEvent<Color4> colour)
{
if (Dropdown is IHasAccentColour dropdown)
dropdown.AccentColour = colour.NewValue;
foreach (var i in TabContainer.Children.OfType<IHasAccentColour>())
i.AccentColour = colour.NewValue;
}
public Color4 StripColour
{
get => strip.Colour;

View File

@ -37,10 +37,10 @@ protected OverlayTabControl()
});
}
protected override void OnAccentColourChanged(ValueChangedEvent<Color4> colour)
protected override void LoadComplete()
{
base.OnAccentColourChanged(colour);
bar.Colour = colour.NewValue;
base.LoadComplete();
AccentColourBindable.BindValueChanged(colour => bar.Colour = colour.NewValue, true);
}
protected override Dropdown<T> CreateDropdown() => null;