1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-26 05:12:57 +08:00
osu-lazer/osu.Game/Screens/Edit/Components/RadioButtons/RadioButton.cs

62 lines
1.6 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
using System;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2020-09-09 17:35:25 +08:00
using osu.Framework.Graphics;
2018-04-13 17:19:50 +08:00
2018-11-06 17:14:46 +08:00
namespace osu.Game.Screens.Edit.Components.RadioButtons
2018-04-13 17:19:50 +08:00
{
public class RadioButton
{
/// <summary>
/// Whether this <see cref="RadioButton"/> is selected.
/// </summary>
public readonly BindableBool Selected;
/// <summary>
/// The item related to this button.
2018-04-13 17:19:50 +08:00
/// </summary>
public object Item;
2018-04-13 17:19:50 +08:00
2020-09-09 17:35:25 +08:00
/// <summary>
/// A function which creates a drawable icon to represent this item. If null, a sane default should be used.
/// </summary>
public readonly Func<Drawable> CreateIcon;
private readonly Action action;
2018-04-13 17:19:50 +08:00
2020-09-09 17:35:25 +08:00
public RadioButton(object item, Action action, Func<Drawable> createIcon = null)
2018-04-13 17:19:50 +08:00
{
Item = item;
2020-09-09 17:35:25 +08:00
CreateIcon = createIcon;
this.action = action;
2018-04-13 17:19:50 +08:00
Selected = new BindableBool();
}
public RadioButton(string item)
: this(item, null)
2018-04-13 17:19:50 +08:00
{
Item = item;
action = null;
2018-04-13 17:19:50 +08:00
}
/// <summary>
/// Selects this <see cref="RadioButton"/>.
/// </summary>
public void Select()
{
if (!Selected.Value)
{
Selected.Value = true;
action?.Invoke();
}
}
2018-04-13 17:19:50 +08:00
/// <summary>
/// Deselects this <see cref="RadioButton"/>.
/// </summary>
public void Deselect() => Selected.Value = false;
}
}