MenuItems
Menu items are the rows inside a Menu. All six types inherit MenuItem, so everything on that page applies to every type. Add any item with:
Menu items
Menu items are the rows inside a Menu. All six types inherit MenuItem, so everything on that page applies to every type. Add any item with:
menu.AddMenuItem(item);The item types
| Type | What it does | Left / right does |
|---|---|---|
| MenuItem | A plain button. Also used to open a submenu. | Right presses the item, left goes back. |
| MenuCheckboxItem | A button with a checkbox on the right. | Right toggles the checkbox. |
| MenuListItem | Picks one value out of a fixed list of strings. | Moves through the list, wrapping around. |
| MenuDynamicListItem | A callback returns the next value. For endless or expensive lists. | Calls your callback for the new value. |
| MenuSliderItem | A slider between a minimum and maximum position. | Moves the slider, without wrapping. |
| SeparatorMenuItem | A centred heading for the rows under it. Pressing it does nothing. | Nothing. |
RightIcon and Label are unavailable on types that draw their own content on the right. Each page lists its limitations.
Example usage
Menu menu = new Menu("Item Types", "One of each");
MenuController.AddMenu(menu);
// A plain button with an icon and text on the right.
menu.AddMenuItem(new MenuItem("Button", "A plain button.")
{
Label = "Right text",
LeftIcon = MenuItem.Icon.STAR
});
// A disabled (greyed out) button.
menu.AddMenuItem(new MenuItem("Locked button", "You can't press me.")
{
Enabled = false,
LeftIcon = MenuItem.Icon.LOCK
});
// A checkbox.
menu.AddMenuItem(new MenuCheckboxItem("Checkbox", "Toggle me.", true));
// A list item.
menu.AddMenuItem(new MenuListItem("List", new List<string>() { "One", "Two", "Three" }, 0, "Pick one."));
// A dynamic list item: the callback decides what the next value is.
string ChangeCallback(MenuDynamicListItem item, bool left)
{
int value = int.Parse(item.CurrentItem);
return (left ? value - 1 : value + 1).ToString();
}
menu.AddMenuItem(new MenuDynamicListItem("Dynamic list", "0", new MenuDynamicListItem.ChangeItemCallback(ChangeCallback), "Counts up and down."));
// A slider.
menu.AddMenuItem(new MenuSliderItem("Slider", 0, 10, 5, true));
// A centred heading for whatever rows come after it. Pressing it does nothing.
menu.AddMenuItem(new SeparatorMenuItem("Section heading"));Reacting to menu items
Each item type raises its own event on the parent menu. OnItemSelect only fires for plain MenuItems. See Events for the full list.
menu.OnItemSelect += (_menu, _item, _index) => { /* plain buttons */ };
menu.OnCheckboxChange += (_menu, _item, _index, _checked) => { /* checkboxes */ };
menu.OnListIndexChange += (_menu, _item, _oldIndex, _newIndex, _itemIndex) => { /* list items */ };Theming and banners
A theme is a stylesheet that overrides MenuAPI's colours, radius, shadow and font. A banner is an image file that replaces the picture at the top of a menu.
MenuItem
A plain button. Every other item type inherits it, so the properties on this page apply to all of them. A MenuItem is also how you open a submenu.