// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using osu.Framework.Graphics.Sprites; namespace osu.Game.Graphics.UserInterface { /// /// An with three possible states. /// public class ThreeStateMenuItem : StatefulMenuItem { /// /// Creates a new . /// /// The text to display. /// The type of action which this performs. public ThreeStateMenuItem(string text, MenuItemType type = MenuItemType.Standard) : this(text, type, null) { } /// /// Creates a new . /// /// The text to display. /// The type of action which this performs. /// A delegate to be invoked when this is pressed. public ThreeStateMenuItem(string text, MenuItemType type, Action action) : this(text, getNextState, type, action) { } /// /// Creates a new . /// /// The text to display. /// A function that mutates a state to another state after this is pressed. /// The type of action which this performs. /// A delegate to be invoked when this is pressed. protected ThreeStateMenuItem(string text, Func changeStateFunc, MenuItemType type, Action action) : base(text, changeStateFunc, type, action) { } public override IconUsage? GetIconForState(ThreeStates state) { switch (state) { case ThreeStates.Indeterminate: return FontAwesome.Regular.Circle; case ThreeStates.Enabled: return FontAwesome.Solid.Check; } return null; } private static ThreeStates getNextState(ThreeStates state) { switch (state) { case ThreeStates.Disabled: return ThreeStates.Enabled; case ThreeStates.Indeterminate: return ThreeStates.Enabled; case ThreeStates.Enabled: return ThreeStates.Disabled; default: throw new ArgumentOutOfRangeException(nameof(state), state, null); } } } }