1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-17 16:33:21 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/TernaryStateMenuItem.cs

80 lines
3.1 KiB
C#
Raw Normal View History

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