2019-01-24 16:43:03 +08:00
|
|
|
// 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
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2017-11-30 14:43:19 +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
|
2017-11-30 14:43:19 +08:00
|
|
|
{
|
2017-11-30 18:49:55 +08:00
|
|
|
public class RadioButton
|
2017-11-30 14:43:19 +08:00
|
|
|
{
|
2017-11-30 18:49:55 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether this <see cref="RadioButton"/> is selected.
|
|
|
|
/// </summary>
|
|
|
|
public readonly BindableBool Selected;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-11-30 14:43:19 +08:00
|
|
|
/// <summary>
|
2020-01-28 14:00:45 +08:00
|
|
|
/// The item related to this button.
|
2017-11-30 14:43:19 +08:00
|
|
|
/// </summary>
|
2021-07-17 01:30:49 +08:00
|
|
|
public string Label;
|
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;
|
|
|
|
|
2020-01-28 14:00:45 +08:00
|
|
|
private readonly Action action;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2021-07-17 01:30:49 +08:00
|
|
|
public RadioButton(string label, Action action, Func<Drawable> createIcon = null)
|
2017-11-30 15:57:30 +08:00
|
|
|
{
|
2021-07-17 01:30:49 +08:00
|
|
|
Label = label;
|
2020-09-09 17:35:25 +08:00
|
|
|
CreateIcon = createIcon;
|
2020-01-28 14:00:45 +08:00
|
|
|
this.action = action;
|
2017-11-30 18:49:55 +08:00
|
|
|
Selected = new BindableBool();
|
2017-11-30 15:57:30 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-11-30 18:49:55 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Selects this <see cref="RadioButton"/>.
|
|
|
|
/// </summary>
|
2020-01-28 14:00:45 +08:00
|
|
|
public void Select()
|
|
|
|
{
|
|
|
|
if (!Selected.Value)
|
|
|
|
{
|
|
|
|
Selected.Value = true;
|
|
|
|
action?.Invoke();
|
|
|
|
}
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-11-30 18:49:55 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Deselects this <see cref="RadioButton"/>.
|
|
|
|
/// </summary>
|
|
|
|
public void Deselect() => Selected.Value = false;
|
2017-11-30 14:43:19 +08:00
|
|
|
}
|
|
|
|
}
|