// 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 TernaryStateMenuItem : StatefulMenuItem { /// /// Creates a new . /// /// The text to display. /// The type of action which this performs. public TernaryStateMenuItem(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 TernaryStateMenuItem(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 TernaryStateMenuItem(string text, Func changeStateFunc, MenuItemType type, Action action) : base(text, changeStateFunc, type, action) { } public override IconUsage? GetIconForState(TernaryState state) { switch (state) { case TernaryState.Indeterminate: return FontAwesome.Solid.DotCircle; case TernaryState.True: return FontAwesome.Solid.Check; } return null; } private static TernaryState getNextState(TernaryState state) { switch (state) { case TernaryState.False: return TernaryState.True; case TernaryState.Indeterminate: return TernaryState.True; case TernaryState.True: return TernaryState.False; default: throw new ArgumentOutOfRangeException(nameof(state), state, null); } } } }