From 011bf095166d88d560087bbf83d07567309c585f Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 8 Nov 2019 13:14:23 +0900 Subject: [PATCH] Add xmldocs and cleanup --- .../TestSceneStatefulMenuItem.cs | 5 ++- .../UserInterface/StatefulMenuItem.cs | 45 +++++++++++++++++++ .../UserInterface/ThreeStateMenuItem.cs | 45 +++++++++++++++++-- .../Graphics/UserInterface/ToggleMenuItem.cs | 14 ++++++ 4 files changed, 104 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs index 00678a6ab4..d010abc862 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneStatefulMenuItem.cs @@ -74,9 +74,10 @@ namespace osu.Game.Tests.Visual.UserInterface case TestStates.State3: return FontAwesome.Solid.DiceThree; - } - return null; + default: + throw new ArgumentOutOfRangeException(nameof(state), state, null); + } } } diff --git a/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs b/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs index b5f9a3d635..0d7b36e51b 100644 --- a/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/StatefulMenuItem.cs @@ -7,15 +7,34 @@ using osu.Framework.Graphics.Sprites; namespace osu.Game.Graphics.UserInterface { + /// + /// An which contains and displays a state. + /// public abstract class StatefulMenuItem : OsuMenuItem { + /// + /// The current state that should be displayed. + /// public readonly Bindable State = new Bindable(); + /// + /// Creates a new . + /// + /// The text to display. + /// A function that mutates a state to another state after this is pressed. + /// The type of action which this performs. protected StatefulMenuItem(string text, Func changeStateFunc, MenuItemType type = MenuItemType.Standard) : this(text, changeStateFunc, type, null) { } + /// + /// Creates a new . + /// + /// The text to display. + /// A function that mutates a state to another state after this is pressed. + /// The type of action which this performs. + /// A delegate to be invoked when this is pressed. protected StatefulMenuItem(string text, Func changeStateFunc, MenuItemType type, Action action) : base(text, type) { @@ -26,19 +45,40 @@ namespace osu.Game.Graphics.UserInterface }; } + /// + /// Retrieves the icon to be displayed for a state. + /// + /// The state to retrieve the relevant icon for. + /// The icon to be displayed for . public abstract IconUsage? GetIconForState(object state); } public abstract class StatefulMenuItem : StatefulMenuItem where T : struct { + /// + /// The current state that should be displayed. + /// public new readonly Bindable State = new Bindable(); + /// + /// Creates a new . + /// + /// The text to display. + /// A function that mutates a state to another state after this is pressed. + /// The type of action which this performs. protected StatefulMenuItem(string text, Func changeStateFunc, MenuItemType type = MenuItemType.Standard) : this(text, changeStateFunc, type, null) { } + /// + /// Creates a new . + /// + /// The text to display. + /// A function that mutates a state to another state after this is pressed. + /// The type of action which this performs. + /// A delegate to be invoked when this is pressed. protected StatefulMenuItem(string text, Func changeStateFunc, MenuItemType type, Action action) : base(text, o => changeStateFunc?.Invoke((T)o) ?? o, type, o => action?.Invoke((T)o)) { @@ -55,6 +95,11 @@ namespace osu.Game.Graphics.UserInterface public sealed override IconUsage? GetIconForState(object state) => GetIconForState((T)state); + /// + /// Retrieves the icon to be displayed for a state. + /// + /// The state to retrieve the relevant icon for. + /// The icon to be displayed for . public abstract IconUsage? GetIconForState(T state); } } diff --git a/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs b/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs index d41a95daa1..e33c68bebd 100644 --- a/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/ThreeStateMenuItem.cs @@ -6,15 +6,41 @@ using osu.Framework.Graphics.Sprites; namespace osu.Game.Graphics.UserInterface { + /// + /// An with three possible states. + /// public class ThreeStateMenuItem : StatefulMenuItem { + /// + /// Creates a new . + /// + /// The text to display. + /// The type of action which this performs. public ThreeStateMenuItem(string text, MenuItemType type = MenuItemType.Standard) : this(text, type, null) { } + /// + /// Creates a new . + /// + /// The text to display. + /// The type of action which this performs. + /// A delegate to be invoked when this is pressed. public ThreeStateMenuItem(string text, MenuItemType type, Action action) - : base(text, getNextState, type, action) + : this(text, getNextState, type, action) + { + } + + /// + /// Creates a new . + /// + /// The text to display. + /// A function that mutates a state to another state after this is pressed. + /// The type of action which this performs. + /// A delegate to be invoked when this is pressed. + protected ThreeStateMenuItem(string text, Func changeStateFunc, MenuItemType type, Action action) + : base(text, changeStateFunc, type, action) { } @@ -44,16 +70,29 @@ namespace osu.Game.Graphics.UserInterface case ThreeStates.Enabled: return ThreeStates.Disabled; - } - return ThreeStates.Disabled; + default: + throw new ArgumentOutOfRangeException(nameof(state), state, null); + } } } public enum ThreeStates { + /// + /// The current state is disabled. + /// Disabled, + + /// + /// The current state is a combination of and . + /// The state becomes if the is pressed. + /// Indeterminate, + + /// + /// The current state is enabled. + /// Enabled } } diff --git a/osu.Game/Graphics/UserInterface/ToggleMenuItem.cs b/osu.Game/Graphics/UserInterface/ToggleMenuItem.cs index f5a442b317..f9ff9859dd 100644 --- a/osu.Game/Graphics/UserInterface/ToggleMenuItem.cs +++ b/osu.Game/Graphics/UserInterface/ToggleMenuItem.cs @@ -6,13 +6,27 @@ using osu.Framework.Graphics.Sprites; namespace osu.Game.Graphics.UserInterface { + /// + /// An which displays an enabled or disabled state. + /// public class ToggleMenuItem : StatefulMenuItem { + /// + /// Creates a new . + /// + /// The text to display. + /// The type of action which this performs. public ToggleMenuItem(string text, MenuItemType type = MenuItemType.Standard) : this(text, type, null) { } + /// + /// Creates a new . + /// + /// The text to display. + /// The type of action which this performs. + /// A delegate to be invoked when this is pressed. public ToggleMenuItem(string text, MenuItemType type, Action action) : base(text, value => !value, type, action) {