hBasic Manual Menu
Commands
|
||||||
Overview
The menu is part of the Actionbar and the actionbar must
be showing in order to use the menu. In hBasic, the menu is shared between the console, graphics and webview. Items may be added and removed. Be aware that if you remove all items, the menu disappears. By default there is one system item showing as explained below. |
||||||
The (Stop / Editor / Exit) System menu
item
In legacy basic two of the above items appear in the
console menu. One is Stop and the other is either
Editor or Exit (for apk). When the program is stopped,
Stop is disabled and vice-versa.
In hBasic this
system menu item has been simplified to just one
item.
It will show Stop or Exit or Editor depending on if the program has stopped or if the app is standard or standalone (apk). When defining a user menu, this system item is recognised as "$stop". The "$" tells hBasic that it is a system item. It is case in-sensitve. System items cannot be disabled but they can be hidden. They will never appear dimmed if shown. System items can be hidden from the menu by not including them in the MENU.SET string. |
||||||
MENU.SET
<itemList_sexp>
Sets the menu to a list of
items
itemList_sexp is a string of labels separated with commas. e.g MENU.SET "Item 1,Item 2,~Item 3,Item 4,Item 5,$stop"
Items
Each supplied item label is entered into the menu in
that order starting with index 1. In the example. the label "Item 1" has index 1. Spaces before and after an item label count as part of the label. Comma is not allowed as part of an item. Normally, an empty Item string is not allowed except to mark an empty menu. Empty Menu
You can create an emtpy menu with an emtpy Item
as the
first Item,
Example
MENU.SET ""
An empty menu will not show the menu (3
dots).
Warning: Because it
is empty, you will not get the system item, so your
program will be harder to debug.
If you need a blank Item as part of a non-empty menu,
then use space(s) instead of an empty string. Disabled Items
By default, all items are enabled (not dimmed). Items that start with a twiddle '~' will be disabled and dimmed. You can use disabled items as labels for menu headers that don't respond to a touch. You can also enable or disable items later on (see menu.enable / menu.disable) System Item
System items begin with a '$'. Therefore do not begin your user items with a "$".
There is only one system item and that is the Stop
item (Stop/Exit/Editor).
The default menu will already contain the system item. If you want the $stop system item in your custom menu, use "$stop" (case insensitive). System items are always enabled (even though they maybe hidden). |
||||||
MENU.ENABLE
<itemList_sexp> | <index_nexp> {,..} MENU.DISABLE <itemList_sexp> | <index_nexp> {,..}
Enables or Disable items. A disabled item will appear dimmed and will not respond to a tap. You can supply multiple items seperated by commas. An item can be a label (string) or it's item index (number). You can also provide a string containing multiple labels (but not numbers). Be careful with spaces, they are counted as part of the label. System items will be ignored. Examples
MENU.ENABLE
"Item 2,Item
3"
MENU.ENABLE 4,5,6 MENU.ENABLE "Item 2,Item 3", 4,5 MENU.DISABLE 4,5, "Item 3" |
||||||
MENU.SHOW
Opens the menu as if you had tapped it.
You can use this to bring up another (changed) menu after the user taps the first menu. |
||||||
MENU.GET {
<label$_svar>} {,
<index_nvar>
}
Get the last tap of a
menu. ExampleEither the label$ or/and the index variable must be given to get the last tapped item. <label$_svar> will be the tapped label string <index_nvar> will be the tapped index (1..n) If the user tapped outside the menu to close it, the index will be 0 and the item will be the empty string "".
MENU.GET
mLabel$
% get just the
label MENU.GET mLabel$, mIndex % get both label and index MENU.GET ,mIndex % get just the index |
||||||
Menu interrupt
block
OnMenuTap: .. MENU.GET.. .. MenuTap.Resume
OnMenuTap
Start of interrupt - is run whenever the user
taps an item in the menu. It is also run if the user taps outside an open menu. If the tap was outside, you will get the an empty string as the label and zero as the index. MenuTap.Resume
End of interrupt routine - will return to the point
that the program got interrupted.
Note :
Statements that run
inside any interrupt block will use the 'main' variable
space. Although functions called inside the block will still run in their own local scope.
Example
? "Tap
the menu"
debug$ = ",$stop" finish = 0 menuSelected = 0 main_menu$ = "~Main Menu,Item 1,Item 2,~disabled item,Quit"+debug$ menu.set main_menu$ do menuSelected = 0 do % wait for a menu selection pause 100 until menuSelected until finish % user quits from menu ? "Done" END do_Menu: % process menu tap MENU.GET label$, m print "Tapped: ";label$,m if label$ = "Quit" then finish = 1 menuSelected = 1 return onMenuTap: % when user taps an open menu gosub do_Menu MenuTap.Resume end |
||||||