1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 06:42:54 +08:00
osu-lazer/osu.Game/Overlays/Settings/SettingsItem.cs

82 lines
2.4 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK.Graphics;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.Sprites;
namespace osu.Game.Overlays.Settings
{
public abstract class SettingsItem<T> : FillFlowContainer, IFilterable
{
protected abstract Drawable CreateControl();
2017-05-04 22:32:27 +08:00
protected Drawable Control { get; }
2017-05-04 22:32:27 +08:00
private IHasCurrentValue<T> controlWithCurrent => Control as IHasCurrentValue<T>;
private SpriteText text;
public virtual string LabelText
{
get { return text?.Text ?? string.Empty; }
set
{
if (text == null)
{
// construct lazily for cases where the label is not needed (may be provided by the Control).
Add(text = new OsuSpriteText { Depth = 1 });
}
text.Text = value;
}
}
// hold a reference to the provided bindable so we don't have to in every settings section.
private Bindable<T> bindable;
public virtual Bindable<T> Bindable
{
get
{
return bindable;
}
set
{
bindable = value;
2017-05-08 09:11:45 +08:00
controlWithCurrent?.Current.BindTo(bindable);
}
}
public string[] FilterTerms => new[] { LabelText };
2017-05-30 15:33:26 +08:00
public bool MatchingFilter
{
set
{
// probably needs a better transition.
this.FadeTo(value ? 1 : 0);
}
}
protected SettingsItem()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Padding = new MarginPadding { Right = 5 };
if ((Control = CreateControl()) != null)
{
2017-05-04 22:32:27 +08:00
if (controlWithCurrent != null)
controlWithCurrent.Current.DisabledChanged += disabled => { Colour = disabled ? Color4.Gray : Color4.White; };
Add(Control);
}
}
}
}