Sidebar

Home



Expressions V4


Tutorials

How-To

Reference

  Lexical basics
  Type system
  Variables and assignment
  Operators
  Expression rules
  Control flow
  Functions
  Built-in functions
   None and NaN
   Arithmetic
   Algebra
   Logarithmic and Exponential
   Trigonometric
   Rounding and Centering
   Strings
   Output, Formatting, Clipboard, and Errors
   Dialog Functions
   Platform and Paths
  Methods and properties
  Built-in methods
   Common Value Methods
   Number Methods
   String Basic Methods
   String Slice Methods
   String Parsing Methods
   String Formatting Methods
   String Regex Methods
   String Trim and Case Methods
  Objects
  Built-in objects
   Global objects
    settings
    controller
    session
    python
   Collections
    array
    map
    bytes
   File Format I/O
    image_data
    image_stream
   Utils
    crypto
    timer
   Comm
    serial
   Dialogs
    file_open
    file_save
    msg_ok
    msg_ok_cancel
    msg_yes_no
    msg_password
   GUI objects
    window
    panel
    group
    splitpanel
    label
    textbutton
    drawablebutton
    togglebutton
    togglegroup
    textinput
    textedit
    numinput
    slider
    combobox
    listbox
    progressbar
    led
    separator
    menu
    image
    snake
  Classes and user-defined objects
  Include system
  Error model
  Execution model and sessions
  Host integration
  Limits and performance
  Formal reference
  Glossary

Cookbook

exprv4:reference:objects:gui_menu

menu

`menu()` creates a menu object that can be attached to a `window()` with `window.menu(menu)`.

Menu groups and menu items are represented by `menu_item` objects. `menu.add(text)` creates a top-level menu group and returns its `menu_item` object. `menu_item.add(…)` then adds submenu items below that group or item.

`menu_item()` is not a public constructor. Create menu items through `menu.add(text)` or `menu_item.add(text)`.

Constructor

Creates a menu object.

Item Description
Syntax `menu()`
Arguments none
Returns menu object
m = menu();
file = m.add('File');

Properties

`menu` currently exposes no public properties.

Common Object Methods

to_string()

Returns a display string for the object.

Item Description
Syntax `value.to_string()`
Arguments none
Returns string

Example:

text = value.to_string();

`clone()` is not supported for `menu`.

Methods

add(text)

Adds a top-level menu group and returns the group as a `menu_item` object.

Item Description
Syntax `menu.add(text)`
Arguments `text`: top-level menu group text
Returns `menu_item` object
m = menu();
file = m.add('File');

menu_item

`menu_item` represents a menu group, submenu, or selectable menu item. It is returned by `menu.add(text)` and `menu_item.add(…)`.

A `menu_item` can contain child items. When an item has children, it is shown as a submenu. When an item has a callback and no children, it is shown as a selectable command.

Constructor

`menu_item` objects are not created with a public constructor.

Item Description
Syntax created by `menu.add(text)` or `menu_item.add(text)`
Arguments not applicable
Returns `menu_item` object
m = menu();
file = m.add('File');
open_item = file.add('Open');

Properties

`menu_item` currently exposes no public properties.

Common Object Methods

to_string()

Returns a display string for the object.

Item Description
Syntax `value.to_string()`
Arguments none
Returns string

Example:

text = value.to_string();

`clone()` is not supported for `menu_item`.

Methods

add(text)

Adds a submenu item below this menu item and returns the new item as a `menu_item` object.

Use this form when the new item will contain child items, or when you want to keep a reference to it before adding children.

Item Description
Syntax `menu_item.add(text)`
Arguments `text`: menu item text
Returns `menu_item` object
m = menu();
file = m.add('File');
recent = file.add('Recent');
recent.add('Job 1');

add(text, callback)

Adds a selectable menu item below this menu item and attaches a callback.

The callback is called with no arguments when the menu item is selected.

Item Description
Syntax `menu_item.add(text, callback)`
Arguments `text`: menu item text; `callback`: callable object to run when selected
Returns `menu_item` object
function open_file()
{
    print('open');
}
 
m = menu();
file = m.add('File');
file.add('Open', open_file);

Example

function open_file()
{
    print('open');
}
 
function save_file()
{
    print('save');
}
 
m = menu();
file = m.add('File');
file.add('Open', open_file);
file.add('Save', save_file);
 
window().title('Menu').menu(m).show();

Previous: separator

Next: image

exprv4/reference/objects/gui_menu.txt · Last modified: by andrej

Page Tools