Class: Toybox.WatchUi.Menu

Inherits:
Toybox.Lang.Object show all

Overview

A representation of an on-screen menu.

A Menu is a special View that presents the user with a list of options. After an option is selected, the registered onMenuItem() method will be called. While a Menu can be generated programmatically, they should generally be created as a resource.

A Menu is pushed using pushView(), which provides a MenuInputDelegate as the input delegate.

See Also:

Note:

The look and feel of a menu is device-specific.

Example:

Build a simple menu programmatically

using Toybox.WatchUi;

class MyBehaviorDelegate extends WatchUi.BehaviorDelegate {
    function initialize() {
        BehaviorDelegate.initialize();
    }

    function onMenu() {
        var menu = new WatchUi.Menu();
        var delegate;
        menu.setTitle("My Menu");
        menu.addItem("Item One", :one);
        menu.addItem("Item Two", :two);
        delegate = new MyMenuDelegate(); // a WatchUi.MenuInputDelegate
        WatchUi.pushView(menu, delegate, WatchUi.SLIDE_IMMEDIATE);
        return true;
    }
}

Since:

API Level 1.0.0

Constant Summary

Constant Variables

Type Name Value Since Description
Type MAX_SIZE 16

API Level 1.0.0

The maximum number of allowed entries in a Menu.

Instance Method Summary collapse

Instance Method Details

addItem(name as Lang.String or Lang.Symbol, identifier as Lang.Symbol) as Void

Add an entry to a Menu.

Parameters:

  • name(Lang.String)

    The item text or the resource identifier of a string resource

  • identifier(Lang.Symbol)

    A Symbol representing the Menu item value

Since:

API Level 1.0.0

setTitle(title as Lang.String or Lang.Symbol) as Void

Set a Menu title.

Parameters:

  • title(Lang.String)

    The title text or the resource identifier of a string resource

Since:

API Level 1.0.0


Generated May 31, 2023 8:48:51 AM