@MENU id, table
Menu
tag in the @DISPLAY
preprocessor command or in the CreateDisplay() call.
You need to pass an identifier for the menu strip to this preprocessor command as well as the actual menu definition. Menus are defined as a tree structure that is composed of a master table that contains various subtables. There are two different types of subtables:
@MENU
must start with a number of menu tables because every menu item needs a
parent menu that it belongs it. These parent menus are described in the menu tables.
You can also nest menus, i.e. it is possible to insert a submenu among a number
of menu items.
Menu item tables recognize the following tags:
ID:
Flags:
#MENUITEM_TOGGLE:
#MENUITEM_SELECTED
flag (see below). The toggle state can be checked by calling the IsMenuItemSelected()
function.
#MENUITEM_RADIO:
#MENUITEM_RADIO
set, will be included in the same radio group. All menu items
inside a radio group will be mutually exclusive, i.e. only one menu item of a radio
group can be active at a time. You can manually modify the state of a radio menu item by
calling the functions SelectMenuItem() or by setting the #MENUITEM_SELECTED
flag (see below).
The radio state can be checked by calling the IsMenuItemSelected()
function. Since radio groups always need an active item, it is not possible to call
DeselectMenuItem() on a radio menu item. If you want to deselect
a radio menu item, you need to select a different radio menu item using SelectMenuItem()
and then the previously selected radio menu item will automatically be deselected. (V7.1)
#MENUITEM_SELECTED:
#MENUITEM_TOGGLE
or #MENUITEM_RADIO
flag to create a toggle or a
radio menu item, you can set this flag to put the menu item into selected state. See above
for more information on toggle and radio menu items.
#MENUITEM_DISABLED:
Hotkey:
Menu strips can also be created at runtime by using the CreateMenu() command. See CreateMenu for details.
You can attach menu strips to displays by using the SetDisplayAttributes()
function or by specifying the Menu
tag in the @DISPLAY preprocessor command or in
the CreateDisplay() call. To detach a menu strip from a display,
call SetDisplayAttributes() passing the special value -1
in the Menu
tag.
To get notified when the user selects items from the menu, you have to listen to
the OnMenuSelect
event handler. This can be done by installing a listener
callback for this event using InstallEventHandler().
See InstallEventHandler for details.
Please note that menu strips are not supported for displays in fullscreen mode. They will only work if your display is in windowed mode.
Note that on Android, it's normally not possible to place menu items in the root level
of the action bar's options menu because on desktop systems menu items always have to
be members of certain root groups (e.g. "File", "Edit", "View", etc.) There can't be
any menu items outside such root groups. When using menu strips on Android, Hollywood
will of course replicate the desktop menu behaviour by creating individual submenus for
those root groups. This means, however, that the user has to tap at least twice to select
a menu item because there won't be any menu items in the root level, they will always be
in submenus instead. So if you don't want Hollywood to create those submenus but just place
all items in the root level, set the SingleMenu
tag in the @DISPLAY
preprocessor command to True
. This is especially useful if there are only a few menu items and
it doesn't make sense to place them in submenus.
Also note that menu strips are currently unsupported on Linux and iOS.
@MENU 1, { {"File", { {"New", ID = "new"}, {"Open...", ID = "open"}, {""}, {"Close", ID = "close", Flags = #MENUITEM_DISABLED}, {""}, {"Save", Flags = #MENUITEM_DISABLED, Hotkey = "S"}, {"Compress", ID = "cmp", Flags = #MENUITEM_TOGGLE}, {""}, {"Export image...", { {"JPEG...", ID = "jpeg"}, {"PNG...", ID = "png"}, {"BMP...", ID = "bmp"}}}, {""}, {"Dump state", ID = "dump"}, {""}, {"Quit", ID = "quit", Hotkey = "Q"}}}, {"Edit", { {"Cut", ID = "cut"}, {"Copy", ID = "copy"}, {"Paste", ID = "paste"}}}, {"?", { {"About...", ID = "about"}}} } @DISPLAY {Menu = 1}The code above creates a menu strip that is attached then attached to the default display.