Class SMMenu
SMMenu: easily create keyboard navigable menus that are real dialog with Android inspired behaviours.
Summary
| Field | Type | Summary |
|---|---|---|
| Items | Collection | Collection of items in the menu |
| Lexicon | Lexicon | Lexicon for translation |
| Title | string | Title of the menu |
| Return type | Function and summary |
|---|---|
| SMMenu | new(string title, Lexicon lexicon) Creates a menu object, this doesn't show it yet. |
| SMMenuItem | addAction(string caption, table args, function func, string roleIcon) Add an item that performs an action when clicked. |
| SMMenuItem | addCheckBox(string caption, value, boolean selected) Add a checkbox item to the menu. |
| SMMenuItem | addRadio(string caption, value, boolean selected) Add a radio item to the menu. |
| SMMenuItem | addSection(string caption) Add a section title in the menu, a single static, not selectable. |
| SMMenuItem | addSubmenu(SMMenu menu, string caption) Add a sub-menu. |
| SMMenuItem | addSwitch(string caption, boolean selected, table args, function func) Add a ON/OFF switch item to the menu, that calls a function once switched. |
| boolean | show() Show the menu. |
Fields
string SMMenu:Title
Title of the menu
Collection SMMenu:Items
Collection of items in the menu
Methods
SMMenu:new(string title, Lexicon lexicon)
Creates a menu object, this doesn't show it yet.
| Parameter | Type | Default | Description |
|---|---|---|---|
| title | string | title | |
| lexicon | Lexicon | lexicon |
- Return
- SMMenu: SMMenu
- Error
- if title is empty string
SMMenu:addCheckBox(string caption, value, boolean selected)
Add a checkbox item to the menu.
It's recommanded then that menu contains only checkboxes.
| Parameter | Type | Default | Description |
|---|---|---|---|
| caption | string | caption | |
| value | caption | Associated value, if nil then value is caption | |
| selected | boolean | false |
- Return
- SMMenuItem: SMMenuItem
- Error
- if caption is empty string
- See
- SMMenu:addSwitch for an alternative which perform actions when (un)checked.
- MenuMultipleChoice for a ready-to-use menu to select one or more values.
SMMenu:addRadio(string caption, value, boolean selected)
Add a radio item to the menu.
It's recommanded then that menu contains only radio items.
| Parameter | Type | Default | Description |
|---|---|---|---|
| caption | string | caption | |
| value | caption | Associated value, if nil then value is caption | |
| selected | boolean | false | Is item selected? Note that only the first selected radio item of a menu is selected, next item can't be selected, only one at a time. |
- Return
- SMMenuItem: SMMenuItem
- Error
- if caption is empty string
- See
- MenuSingleChoice for a ready-to-use menu to select only one value.
SMMenu:addSwitch(string caption, boolean selected, table args, function func)
Add a ON/OFF switch item to the menu, that calls a function once switched.
For a multi-choice, it is recommanded to add only checkboxes. 
| Parameter | Type | Default | Description |
|---|---|---|---|
| caption | string | caption | |
| selected | boolean | nil | true = ON, false = OFF, nil = unknown |
| args | table | Table of arguments for func | |
| func | function | Function called just before switch is changed ON/OFF, syntax: function(args, state[, menuItem]) where:
true if the switch must be interrupted (e.g. after user cancel of a Confirmation(...)), returns false, nil or nothing to continue switching. |
- Return
- SMMenuItem: SMMenuItem
- Error
- if caption is empty string
- See
- SMMenu:addCheckBox
SMMenu:addSubmenu(SMMenu menu, string caption)
Add a sub-menu.
| Parameter | Type | Default | Description |
|---|---|---|---|
| menu | SMMenu | menu | |
| caption | string | menu.Title |
- Return
- SMMenuItem: SMMenuItem
- Error
- if caption is empty string
SMMenu:addAction(string caption, table args, function func, string roleIcon)
Add an item that performs an action when clicked.
| Parameter | Type | Default | Description |
|---|---|---|---|
| caption | string | caption | |
| args | table | Table of arguments for func | |
| func | function | Function that receive args table and menuItem, the object created by addAction(...) that may be used to enable/disable next items with the following code menuItem.Next:disable(false). func returns true if the menu should close after call. | |
| roleIcon | string | nil | Special keyword that will draw an icon on the right:
|
- Return
- SMMenuItem: SMMenuItem
- Error
- if caption is empty string
- Example
myMenu:addAction("Edit general tempo", {FrontScore()}, function(args) return args[1].EditGeneralTempo(); end, "dialog")
SMMenu:addSection(string caption)
Add a section title in the menu, a single static, not selectable.
| Parameter | Type | Default | Description |
|---|---|---|---|
| caption | string | caption |
- Return
- SMMenuItem: SMMenuItem
- Error
- if caption is empty string
SMMenu:show()
Show the menu.
- Return
- boolean:
trueif the parent menu should be closed too,falseif not (user clicked "Back"/"Cancel" button)