mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Rename ThreeState -> TernaryState and add basic tests
This commit is contained in:
@ -0,0 +1,65 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osuTK.Input;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
|
{
|
||||||
|
public class TestSceneTernaryMenuItem : ManualInputManagerTestScene
|
||||||
|
{
|
||||||
|
private readonly OsuMenu menu;
|
||||||
|
|
||||||
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
|
{
|
||||||
|
typeof(OsuMenu),
|
||||||
|
typeof(ThreeStateMenuItem),
|
||||||
|
typeof(DrawableStatefulMenuItem)
|
||||||
|
};
|
||||||
|
|
||||||
|
private readonly Bindable<TernaryState> state = new Bindable<TernaryState>(TernaryState.Indeterminate);
|
||||||
|
|
||||||
|
public TestSceneTernaryMenuItem()
|
||||||
|
{
|
||||||
|
Add(menu = new OsuMenu(Direction.Vertical, true)
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Items = new[]
|
||||||
|
{
|
||||||
|
new ThreeStateMenuItem("First"),
|
||||||
|
new ThreeStateMenuItem("Second") { State = { BindTarget = state } },
|
||||||
|
new ThreeStateMenuItem("Third") { State = { Value = TernaryState.True } },
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
checkState(TernaryState.Indeterminate);
|
||||||
|
|
||||||
|
click();
|
||||||
|
checkState(TernaryState.True);
|
||||||
|
|
||||||
|
click();
|
||||||
|
checkState(TernaryState.False);
|
||||||
|
|
||||||
|
click();
|
||||||
|
checkState(TernaryState.True);
|
||||||
|
|
||||||
|
click();
|
||||||
|
checkState(TernaryState.False);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void click() =>
|
||||||
|
AddStep("click", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(menu.ScreenSpaceDrawQuad.Centre);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
private void checkState(TernaryState expected)
|
||||||
|
=> AddAssert($"state is {expected}", () => state.Value == expected);
|
||||||
|
}
|
||||||
|
}
|
@ -1,35 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Game.Graphics.UserInterface;
|
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
|
||||||
{
|
|
||||||
public class TestSceneThreeStateMenuItem : OsuTestScene
|
|
||||||
{
|
|
||||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
|
||||||
{
|
|
||||||
typeof(OsuMenu),
|
|
||||||
typeof(ThreeStateMenuItem),
|
|
||||||
typeof(DrawableStatefulMenuItem)
|
|
||||||
};
|
|
||||||
|
|
||||||
public TestSceneThreeStateMenuItem()
|
|
||||||
{
|
|
||||||
Add(new OsuMenu(Direction.Vertical, true)
|
|
||||||
{
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
Items = new[]
|
|
||||||
{
|
|
||||||
new ThreeStateMenuItem("First"),
|
|
||||||
new ThreeStateMenuItem("Second") { State = { Value = ThreeStates.Indeterminate } },
|
|
||||||
new ThreeStateMenuItem("Third") { State = { Value = ThreeStates.Enabled } },
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,22 +6,22 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// An on/off state with an extra indeterminate state.
|
/// An on/off state with an extra indeterminate state.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum ThreeStates
|
public enum TernaryState
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current state is disabled.
|
/// The current state is false.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Disabled,
|
False,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current state is a combination of <see cref="Disabled"/> and <see cref="Enabled"/>.
|
/// The current state is a combination of <see cref="False"/> and <see cref="True"/>.
|
||||||
/// The state becomes <see cref="Enabled"/> if the <see cref="ThreeStateMenuItem"/> is pressed.
|
/// The state becomes <see cref="True"/> if the <see cref="ThreeStateMenuItem"/> is pressed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Indeterminate,
|
Indeterminate,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current state is enabled.
|
/// The current state is true.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Enabled
|
True
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,7 +9,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// An <see cref="OsuMenuItem"/> with three possible states.
|
/// An <see cref="OsuMenuItem"/> with three possible states.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ThreeStateMenuItem : StatefulMenuItem<ThreeStates>
|
public class ThreeStateMenuItem : StatefulMenuItem<TernaryState>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="ThreeStateMenuItem"/>.
|
/// Creates a new <see cref="ThreeStateMenuItem"/>.
|
||||||
@ -27,7 +27,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
/// <param name="text">The text to display.</param>
|
/// <param name="text">The text to display.</param>
|
||||||
/// <param name="type">The type of action which this <see cref="ThreeStateMenuItem"/> performs.</param>
|
/// <param name="type">The type of action which this <see cref="ThreeStateMenuItem"/> performs.</param>
|
||||||
/// <param name="action">A delegate to be invoked when this <see cref="ThreeStateMenuItem"/> is pressed.</param>
|
/// <param name="action">A delegate to be invoked when this <see cref="ThreeStateMenuItem"/> is pressed.</param>
|
||||||
public ThreeStateMenuItem(string text, MenuItemType type, Action<ThreeStates> action)
|
public ThreeStateMenuItem(string text, MenuItemType type, Action<TernaryState> action)
|
||||||
: this(text, getNextState, type, action)
|
: this(text, getNextState, type, action)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -39,37 +39,37 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
/// <param name="changeStateFunc">A function that mutates a state to another state after this <see cref="ThreeStateMenuItem"/> is pressed.</param>
|
/// <param name="changeStateFunc">A function that mutates a state to another state after this <see cref="ThreeStateMenuItem"/> is pressed.</param>
|
||||||
/// <param name="type">The type of action which this <see cref="ThreeStateMenuItem"/> performs.</param>
|
/// <param name="type">The type of action which this <see cref="ThreeStateMenuItem"/> performs.</param>
|
||||||
/// <param name="action">A delegate to be invoked when this <see cref="ThreeStateMenuItem"/> is pressed.</param>
|
/// <param name="action">A delegate to be invoked when this <see cref="ThreeStateMenuItem"/> is pressed.</param>
|
||||||
protected ThreeStateMenuItem(string text, Func<ThreeStates, ThreeStates> changeStateFunc, MenuItemType type, Action<ThreeStates> action)
|
protected ThreeStateMenuItem(string text, Func<TernaryState, TernaryState> changeStateFunc, MenuItemType type, Action<TernaryState> action)
|
||||||
: base(text, changeStateFunc, type, action)
|
: base(text, changeStateFunc, type, action)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IconUsage? GetIconForState(ThreeStates state)
|
public override IconUsage? GetIconForState(TernaryState state)
|
||||||
{
|
{
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case ThreeStates.Indeterminate:
|
case TernaryState.Indeterminate:
|
||||||
return FontAwesome.Regular.Circle;
|
return FontAwesome.Solid.DotCircle;
|
||||||
|
|
||||||
case ThreeStates.Enabled:
|
case TernaryState.True:
|
||||||
return FontAwesome.Solid.Check;
|
return FontAwesome.Solid.Check;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ThreeStates getNextState(ThreeStates state)
|
private static TernaryState getNextState(TernaryState state)
|
||||||
{
|
{
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case ThreeStates.Disabled:
|
case TernaryState.False:
|
||||||
return ThreeStates.Enabled;
|
return TernaryState.True;
|
||||||
|
|
||||||
case ThreeStates.Indeterminate:
|
case TernaryState.Indeterminate:
|
||||||
return ThreeStates.Enabled;
|
return TernaryState.True;
|
||||||
|
|
||||||
case ThreeStates.Enabled:
|
case TernaryState.True:
|
||||||
return ThreeStates.Disabled;
|
return TernaryState.False;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException(nameof(state), state, null);
|
throw new ArgumentOutOfRangeException(nameof(state), state, null);
|
||||||
|
Reference in New Issue
Block a user