osu/osu.Game/Graphics/UserInterface/TernaryStateMenuItem.cs

70 lines
2.7 KiB
C#
Raw Normal View History

2019-11-08 03:47:42 +00: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.
2019-11-08 03:55:22 +00:00
using System;
2019-11-08 03:47:42 +00:00
using osu.Framework.Graphics.Sprites;
namespace osu.Game.Graphics.UserInterface
{
2019-11-08 04:14:23 +00:00
/// <summary>
/// An <see cref="OsuMenuItem"/> with three possible states.
/// </summary>
2019-11-12 01:18:25 +00:00
public class TernaryStateMenuItem : StatefulMenuItem<TernaryState>
2019-11-08 03:47:42 +00:00
{
2019-11-08 04:14:23 +00:00
/// <summary>
2019-11-12 01:18:25 +00:00
/// Creates a new <see cref="TernaryStateMenuItem"/>.
2019-11-08 04:14:23 +00:00
/// </summary>
/// <param name="text">The text to display.</param>
2019-11-12 01:18:25 +00:00
/// <param name="type">The type of action which this <see cref="TernaryStateMenuItem"/> performs.</param>
/// <param name="action">A delegate to be invoked when this <see cref="TernaryStateMenuItem"/> is pressed.</param>
2020-05-26 04:51:53 +00:00
public TernaryStateMenuItem(string text, MenuItemType type = MenuItemType.Standard, Action<TernaryState> action = null)
2019-11-08 04:14:23 +00:00
: this(text, getNextState, type, action)
{
}
/// <summary>
2019-11-12 01:18:25 +00:00
/// Creates a new <see cref="TernaryStateMenuItem"/>.
2019-11-08 04:14:23 +00:00
/// </summary>
/// <param name="text">The text to display.</param>
2019-11-12 01:18:25 +00:00
/// <param name="changeStateFunc">A function that mutates a state to another state after this <see cref="TernaryStateMenuItem"/> is pressed.</param>
/// <param name="type">The type of action which this <see cref="TernaryStateMenuItem"/> performs.</param>
/// <param name="action">A delegate to be invoked when this <see cref="TernaryStateMenuItem"/> is pressed.</param>
protected TernaryStateMenuItem(string text, Func<TernaryState, TernaryState> changeStateFunc, MenuItemType type, Action<TernaryState> action)
2019-11-08 04:14:23 +00:00
: base(text, changeStateFunc, type, action)
2019-11-08 03:47:42 +00:00
{
}
public override IconUsage? GetIconForState(TernaryState state)
2019-11-08 03:47:42 +00:00
{
switch (state)
{
case TernaryState.Indeterminate:
return FontAwesome.Solid.DotCircle;
2019-11-08 03:47:42 +00:00
case TernaryState.True:
2019-11-08 03:47:42 +00:00
return FontAwesome.Solid.Check;
}
return null;
}
private static TernaryState getNextState(TernaryState state)
2019-11-08 03:47:42 +00:00
{
switch (state)
{
case TernaryState.False:
return TernaryState.True;
2019-11-08 03:47:42 +00:00
case TernaryState.Indeterminate:
return TernaryState.True;
2019-11-08 03:47:42 +00:00
case TernaryState.True:
return TernaryState.False;
2019-11-08 03:47:42 +00:00
2019-11-08 04:14:23 +00:00
default:
throw new ArgumentOutOfRangeException(nameof(state), state, null);
}
2019-11-08 03:47:42 +00:00
}
}
}