Add basic implementation of a toggleable menu item

This commit is contained in:
smoogipoo
2019-11-07 22:26:35 +09:00
parent 29672c48e1
commit c3a3b4091b
5 changed files with 132 additions and 5 deletions

View File

@ -0,0 +1,25 @@
// 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 osu.Framework.Bindables;
namespace osu.Game.Graphics.UserInterface
{
public class ToggleMenuItem : OsuMenuItem
{
public readonly BindableBool State = new BindableBool();
public ToggleMenuItem(string text, MenuItemType type = MenuItemType.Standard)
: this(text, type, null)
{
}
public ToggleMenuItem(string text, MenuItemType type, Action<bool> action)
: base(text, type)
{
Action.Value = () => State.Toggle();
State.BindValueChanged(state => action?.Invoke(state.NewValue));
}
}
}