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

Constant Summary

DividerType

Divider type for supported devices

Since:

API Level 5.0.1

Name Value Since Description See Also
DIVIDER_TYPE_DEFAULT 0

API Level 5.0.1

Default divider type

DIVIDER_TYPE_ICON 1

API Level 5.0.1

Icon divider type

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

Retrieve the icon for this Menu2.

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, :dividerType as Menu2.DividerType 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.

Note:

The :dividerType option is only used on ConnectIQ 5.0.1 devices with divider support.

Parameters:

See Also:

Since:

API Level 3.0.0

setDividerType(divider as Menu2.DividerType or Null) as Void

Set or change the desired divider type.

If set to Menu2.DIVIDER_TYPE_ICON.

For IconMenuItem and CheckboxMenuItem, icon and checkbox will be rendered on the left side of the divider if item is MenuItem.MENU_ITEM_LABEL_ALIGN_LEFT or default aligned.

For ToggleMenuItem, toggle icon will be rendered on the left side of the divider, if item is MenuItem.MENU_ITEM_LABEL_ALIGN_LEFT aligned only.

Menu2.DIVIDER_TYPE_DEFAULT will be used if not set for devices that support divider, or null is passed.

Supported Devices:

Since:

API Level 5.0.1

Throws:

  • (WatchUi.InvalidValueException)

    Thrown if divider is not an valid value.

  • (Lang.UnexpectedTypeException)

    Thrown if divider is not a valid type.

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

Set the icon to display in the subscreen area when the focused MenuItem does not have an icon. If this menu does not have an icon, 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 Sep 23, 2024, 3:32:49 PM