Class SMMenu

SMMenu: easily create keyboard navigable menus that are real dialog with Android inspired behaviours.

Summary

FieldTypeSummary
ItemsCollectionCollection of items in the menu
LexiconLexiconLexicon for translation
TitlestringTitle of the menu
Return typeFunction and summary
SMMenunew(string title, Lexicon lexicon)
Creates a menu object, this doesn't show it yet.
SMMenuItemaddAction(string caption, table args, function func, string roleIcon)
Add an item that performs an action when clicked.
SMMenuItemaddCheckBox(string caption, value, boolean selected)
Add a checkbox item to the menu.
SMMenuItemaddRadio(string caption, value, boolean selected)
Add a radio item to the menu.
SMMenuItemaddSection(string caption)
Add a section title in the menu, a single static, not selectable.
SMMenuItemaddSubmenu(SMMenu menu, string caption)
Add a sub-menu.
SMMenuItemaddSwitch(string caption, boolean selected, table args, function func)
Add a ON/OFF switch item to the menu, that calls a function once switched.
booleanshow()
Show the menu.

Fields

string SMMenu:Title

Title of the menu

Collection SMMenu:Items

Collection of items in the menu

Lexicon SMMenu:Lexicon

Lexicon for translation

Methods

SMMenu:new(string title, Lexicon lexicon)

Creates a menu object, this doesn't show it yet.

ParameterTypeDefaultDescription
titlestring title
lexiconLexicon 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.

ParameterTypeDefaultDescription
captionstring caption
value captionAssociated value, if nil then value is caption
selectedbooleanfalse 
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.

ParameterTypeDefaultDescription
captionstring caption
value captionAssociated value, if nil then value is caption
selectedbooleanfalseIs 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.

Each switch call a function while music play.

ParameterTypeDefaultDescription
captionstring caption
selectedbooleanniltrue = ON, false = OFF, nil = unknown
argstable Table of arguments for func
funcfunction Function called just before switch is changed ON/OFF, syntax: function(args, state[, menuItem]) where:
  1. args is the table args argument of addSwitch(...)
  2. state is the new state on/off, boolean.
  3. menuItem (optional): SMMenuItem object returned by addSwitch(...), that may be use to disable next item with code menuItem.Next:disable(true)
Returns 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.

ParameterTypeDefaultDescription
menuSMMenu menu
captionstringmenu.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.

ParameterTypeDefaultDescription
captionstring caption
argstable Table of arguments for func
funcfunction 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.
roleIconstringnilSpecial keyword that will draw an icon on the right:
  • "dialog" draws ...(ellipsis)
  • "menu" draws the same right oriented triangle as submenus
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.

ParameterTypeDefaultDescription
captionstring caption
Return
SMMenuItem: SMMenuItem
Error
if caption is empty string

SMMenu:show()

Show the menu.

Return
boolean: true if the parent menu should be closed too, false if not (user clicked "Back"/"Cancel" button)