mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 15:33:05 +08:00
Implement a three-state menu item
This commit is contained in:
parent
ce08d664a5
commit
30f877c4ab
@ -0,0 +1,35 @@
|
||||
// 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 } },
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
53
osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs
Normal file
53
osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs
Normal file
@ -0,0 +1,53 @@
|
||||
// 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 osu.Framework.Graphics.Sprites;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public class ThreeStateMenuItem : StatefulMenuItem<ThreeStates>
|
||||
{
|
||||
public ThreeStateMenuItem(string text, MenuItemType type = MenuItemType.Standard)
|
||||
: base(text, type, getNextState)
|
||||
{
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return ThreeStates.Disabled;
|
||||
}
|
||||
}
|
||||
|
||||
public enum ThreeStates
|
||||
{
|
||||
Disabled,
|
||||
Indeterminate,
|
||||
Enabled
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user