mirror of
https://github.com/ppy/osu.git
synced 2025-02-19 21:43:21 +08:00
Cleanup OsuTabControl.AccentColour
This commit is contained in:
parent
87af482823
commit
bf2b71f7dd
@ -17,12 +17,19 @@ using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public class OsuTabControl<T> : TabControl<T>
|
||||
{
|
||||
private readonly Bindable<Color4> accentColour = new Bindable<Color4>();
|
||||
|
||||
public Color4 AccentColour
|
||||
{
|
||||
get => accentColour.Value;
|
||||
set => accentColour.Value = value;
|
||||
}
|
||||
|
||||
private readonly Box strip;
|
||||
|
||||
protected override Dropdown<T> CreateDropdown() => new OsuTabDropdown();
|
||||
@ -60,24 +67,22 @@ namespace osu.Game.Graphics.UserInterface
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
if (accentColour == default)
|
||||
if (accentColour.Value == default)
|
||||
AccentColour = colours.Blue;
|
||||
}
|
||||
|
||||
private Color4 accentColour;
|
||||
|
||||
public Color4 AccentColour
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
get => accentColour;
|
||||
set
|
||||
{
|
||||
accentColour = value;
|
||||
if (Dropdown is IHasAccentColour dropdown)
|
||||
dropdown.AccentColour = value;
|
||||
foreach (var i in TabContainer.Children.OfType<IHasAccentColour>())
|
||||
i.AccentColour = value;
|
||||
InternalChildren.OfType<IHasAccentColour>().ForEach(c => c.AccentColour = value);
|
||||
}
|
||||
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
|
||||
|
@ -1,8 +1,8 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input.Events;
|
||||
@ -16,7 +16,7 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
public abstract class OverlayTabControl<T> : OsuTabControl<T>
|
||||
{
|
||||
private readonly TabControlBar bar;
|
||||
private readonly Box bar;
|
||||
|
||||
protected float BarHeight
|
||||
{
|
||||
@ -28,7 +28,7 @@ namespace osu.Game.Overlays
|
||||
TabContainer.Masking = false;
|
||||
TabContainer.Spacing = new Vector2(15, 0);
|
||||
|
||||
AddInternal(bar = new TabControlBar
|
||||
AddInternal(bar = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 2,
|
||||
@ -37,6 +37,12 @@ namespace osu.Game.Overlays
|
||||
});
|
||||
}
|
||||
|
||||
protected override void OnAccentColourChanged(ValueChangedEvent<Color4> colour)
|
||||
{
|
||||
base.OnAccentColourChanged(colour);
|
||||
bar.Colour = colour.NewValue;
|
||||
}
|
||||
|
||||
protected override Dropdown<T> CreateDropdown() => null;
|
||||
|
||||
protected override TabItem<T> CreateTabItem(T value) => new OverlayTabItem(value);
|
||||
@ -138,24 +144,5 @@ namespace osu.Game.Overlays
|
||||
Text.FadeColour(AccentColour, 120, Easing.InQuad);
|
||||
}
|
||||
}
|
||||
|
||||
private class TabControlBar : CompositeDrawable, IHasAccentColour
|
||||
{
|
||||
public Color4 AccentColour
|
||||
{
|
||||
get => background.Colour;
|
||||
set => background.Colour = value;
|
||||
}
|
||||
|
||||
private readonly Box background;
|
||||
|
||||
public TabControlBar()
|
||||
{
|
||||
AddInternal(background = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user