Class: Toybox.WatchUi.Menu2

Overview

A representation of an on-screen menu. A Menu2 is a special View, similar to a Toybox::WatchUi::Menu, that presents the user with a list of options. A Menu2 offers more capabilities than a Toybox::WatchUi::Menu, like graphical titles, menu items that can be updated dynamically, and additional menu elements such as check boxes.

After an option is selected, the registered onSelect() method will be called. While a Menu2 can be generated programmatically, they should generally be created as a resource.

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

See Also:

Note:

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

Example:

Build a simple Menu2 programmatically

using Toybox.WatchUi;

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

    function onMenu() {
        var menu = new WatchUi.Menu2({:title=>"My Menu2"});
        var delegate;
        menu.addItem(
            new MenuItem(
                "Item 1 Label",
                "Item 1 subLabel",
                "itemOneId",
                {}
            )
        );
        menu.addItem(
            new MenuItem(
                "Item 2 Label",
                "Item 2 subLabel",
                "itemTwoId",
                {}
            )
        );
        delegate = new MyMenu2Delegate(); // a WatchUi.Menu2InputDelegate
        WatchUi.pushView(menu, delegate, WatchUi.SLIDE_IMMEDIATE);
        return true;
    }
}

Since:

API Level 3.0.0

Supported Devices:

Direct Known Subclasses

WatchUi.CheckboxMenu, WatchUi.CustomMenu

Instance Method Summary collapse

Instance Method Details

addItem(item as WatchUi.MenuItem) as Void

Add a MenuItem to a Menu2.

Parameters:

Since:

API Level 3.0.0

Throws:

deleteItem(index as Lang.Number) as Lang.Boolean or Null

Delete a MenuItem from a Menu2.

Parameters:

Returns:

  • Toybox::Lang::Boolean true if the item exists, or null if the specified index it outside of the bounds of the menu items array.

Since:

API Level 3.0.0

findItemById(identifier as Lang.Object) as Lang.Number

Find a MenuItem by ID in a Menu2.

Parameters:

  • identifier(Lang.Object)

    The identifier for which to search

Returns:

Since:

API Level 3.0.0

getIcon() as Graphics.BitmapType or WatchUi.Drawable or Null

Get the icon

The icon that is used for the subscreen area will be returned If an icon is not been specified, this function will return null

Supported Devices:

Returns:

Since:

API Level 3.4.0

getItem(index as Lang.Number) as WatchUi.MenuItem or Null

Get a MenuItem from a Menu2.

Parameters:

Returns:

Since:

API Level 3.0.0

initialize(options as { :title as Lang.String or Lang.ResourceId or WatchUi.Drawable, :focus as Lang.Number, :icon as Graphics.BitmapType or WatchUi.Drawable or Lang.ResourceId, :theme as WatchUi.MenuTheme or Null } or Null)

Constructor

Note:

The :icon option is only used on ConnectIQ 3.4.0 devices with subscreen support.

Note:

The :theme option is only used on ConnectIQ 4.1.8 devices with menu theme support.

Parameters:

Since:

API Level 3.0.0

setFocus(focus as Lang.Number or Null) as Void

Set the focus of a MenuItem in a Menu2.

Parameters:

Since:

API Level 3.0.0

Throws:

setIcon(icon as Graphics.BitmapType or WatchUi.Drawable or Lang.ResourceId or Null) as Void

Set the icon

The specified icon will be displayed in the subscreen area when this Menu2 item is visible. If an icon is not been specified, the app icon will be shown instead.

Parameters:

Supported Devices:

Since:

API Level 3.4.0

setTheme(theme as WatchUi.MenuTheme or Null) as Void

Set the theme

Parameters:

Supported Devices:

Since:

API Level 4.1.8

setTitle(title as Lang.String or Lang.ResourceId or WatchUi.Drawable or Null) as Void

Set a Menu2 title.

Parameters:

Since:

API Level 3.0.0

Throws:

updateItem(item as WatchUi.MenuItem, index as Lang.Number) as Void

Update a MenuItem in a Menu2.

Parameters:

Since:

API Level 3.0.0


Generated Apr 17, 2024 9:40:39 AM