See menu-template branch.
Allows the user to create a Menu based on the properties and methods of a class that inherits MenuTemplate via attributes.
All item attributes specifiy at least three properties: Name, Text and Description. Name is used to reference the MenuItem (for example, to access the MenuItem instance with MenuTemplate.GetItemByName), if null, the property name will be used.
API
MenuTemplate
Base class for menu templates. Implements INotifyPropertyChanged.
The method BuildMenu creates the menu and sets the property Menu.
MenuAttribute
Defines the basic properties of a Menu: Title, Subtitle and Theme. Required to build the menu from a template class.
[Menu(Title = "My Menu", Subtitle = "Subtitle for my menu")]
private class TestMenu : MenuTemplate
MenuItemAttribute
Defines a property as a MenuItem. The property type must be a delegate or a type that has an Invoke method with either of the following signatures:
void Invoke();
void Invoke(MenuItem);
The delegate or method will be executed when the MenuItem.Activated event is raised.
Defines a property as a MenuItemCheckbox. The property type must be bool. If the create checkbox item is checked or unchecked the property value will be updated. And in the other way around, if the property setter raises the INotifyPropertyChanged.PropertyChanged event, changing the value via the property setter the checkbox item IsChecked property will be updated too.
[MenuItemCheckbox(Text = "ItemText")]
public bool BoolValue
{
get => boolValue;
set => SetProperty(ref doSomeOtherThing, value);
}
Note, SetProperty is a method provided by MenuTemplate that raises the PropertyChanged event.
MenuItemNumericScrollerAttribute
Similar to MenuItemCheckboxAttribute but for properties of numeric types. Also provides properties to customize the MenuItemNumericScroller created: Minimum, Maximum, Increment, ThousandsSeparator, Hexadecimal and DecimalPlaces.
[MenuItemNumericScroller(Text = "ItemText")]
public float FloatValue
{
get => floatValue;
set => SetProperty(ref floatValue, value);
}
[MenuItemNumericScroller(Text = "ItemText", Increment = 1.0, DecimalPlaces = 0)]
public int IntValue
{
get => intValue;
set => SetProperty(ref intValue, value, nameof(IntValue), nameof(IntValueAsHex));
}
[MenuItemNumericScroller(Text = "Int Value as Hex", Increment = 1.0, DecimalPlaces = 0, Hexadecimal = true)]
private int IntValueAsHex
{
get => IntValue;
set => IntValue = value;
}
MenuItemEnumScroller
Similar to MenuItemCheckboxAttribute and MenuItemNumericScrollerAttribute but for properties of enum types.
[MenuItemEnumScroller(Text = "ItemText")]
public GameControl EnumValue
{
get => enumValue;
set => SetProperty(ref enumValue, value);
}
MenuItemActivatedHandlerAttribute
Defines a method as a MenuItem.Activated event handler for a specific set of items. The Items string array contains the names of the wanted menu items.
See menu-template branch. Allows the user to create a
Menu
based on the properties and methods of a class that inheritsMenuTemplate
via attributes. All item attributes specifiy at least three properties:Name
,Text
andDescription
.Name
is used to reference theMenuItem
(for example, to access theMenuItem
instance withMenuTemplate.GetItemByName
), if null, the property name will be used.API
MenuTemplate
Base class for menu templates. Implements
INotifyPropertyChanged
. The methodBuildMenu
creates the menu and sets the propertyMenu
.MenuAttribute
Defines the basic properties of a
Menu
:Title
,Subtitle
andTheme
. Required to build the menu from a template class.MenuItemAttribute
Defines a property as a
MenuItem
. The property type must be a delegate or a type that has anInvoke
method with either of the following signatures:The delegate or method will be executed when the
MenuItem.Activated
event is raised.MenuItemCheckboxAttribute
Defines a property as a
MenuItemCheckbox
. The property type must bebool
. If the create checkbox item is checked or unchecked the property value will be updated. And in the other way around, if the property setter raises theINotifyPropertyChanged.PropertyChanged
event, changing the value via the property setter the checkbox itemIsChecked
property will be updated too.Note,
SetProperty
is a method provided byMenuTemplate
that raises thePropertyChanged
event.MenuItemNumericScrollerAttribute
Similar to
MenuItemCheckboxAttribute
but for properties of numeric types. Also provides properties to customize theMenuItemNumericScroller
created:Minimum
,Maximum
,Increment
,ThousandsSeparator
,Hexadecimal
andDecimalPlaces
.MenuItemEnumScroller
Similar to
MenuItemCheckboxAttribute
andMenuItemNumericScrollerAttribute
but for properties of enum types.MenuItemActivatedHandlerAttribute
Defines a method as a
MenuItem.Activated
event handler for a specific set of items. TheItems
string array contains the names of the wanted menu items.TBD