Class: Toybox.WatchUi.CustomMenu

Overview

A representation of a custom menu.

A CustomMenu is a specialized Menu2 View that presents the user with a list of custom rendered options. After an option is selected, the registered onSelect() method will be called.

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

See Also:

Example:

Build a CustomMenu programmatically

using Toybox.WatchUi;

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

    function onMenu() {
        var menu = new WatchUi.CustomMenu(80, Graphics.COLOR_BLACK, {});

        menu.addItem(
            new MyCustomMenuItem( // a WatchUi.CustomMenuItem
                :itemOne,
                {}
            )
        );
        menu.addItem(
            new MyCustomMenuItem( // a WatchUi.CustomMenuItem
                :itemTwo,
                {}
            )
        );
        var delegate = new MyMenu2Delegate(); // a WatchUi.Menu2InputDelegate
        WatchUi.pushView(menu, delegate, WatchUi.SLIDE_IMMEDIATE);
        return true;
    }
}

Since:

API Level 3.0.0

Supported Devices:

Instance Method Summary collapse

Instance Method Details

addItem(item as WatchUi.CustomMenuItem) as Void

Add a CustomMenuItem to a CustomMenu.

Parameters:

  • item(WatchUi.CustomMenuItem)

    The CustomMenuItem to add to the CustomMenu. Other MenuItem variants cannot be added to a Custom Menu.

Since:

API Level 3.0.0

Throws:

drawFooter(dc as Graphics.Dc) as Void

Draw the CustomMenu footer.

This is called to render the menu footer region.

Parameters:

Since:

API Level 3.0.0

drawForeground(dc as Graphics.Dc) as Void

Draw the CustomMenu foreground.

This is called after a menu's items and title have been rendered. It can be used to draw overlay content for the menu.

Parameters:

Since:

API Level 3.0.0

drawTitle(dc as Graphics.Dc) as Void

Draw the CustomMenu title.

This is called to render the menu title region.

Parameters:

Since:

API Level 3.0.0

initialize(itemHeight as Lang.Number, backgroundColor as Graphics.ColorType, options as { :focus as Lang.Number, :focusItemHeight as Lang.Number or Null, :title as WatchUi.Drawable, :footer as WatchUi.Drawable, :foreground as WatchUi.Drawable, :icon as Graphics.BitmapType or WatchUi.Drawable or Lang.ResourceId, :titleItemHeight as Lang.Number or Null, :footerItemHeight as Lang.Number or Null, :theme as WatchUi.MenuTheme or Null, :dividerType as Menu2.DividerType or Null } or Null)

Constructor

Note:

The options :titleItemHeight and :footerItemHeight are only supported with ConnectIQ 4.0.0 and later.

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. The background color will not be used if themes are supported and the theme is non-null.

Note:

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

Parameters:

  • itemHeight(Lang.Number)

    The pixel height of menu items rendered by this menu.

  • backgroundColor(Graphics.ColorType)

    The color that will be used to fill the background of the menu.

  • options(Lang.Dictionary)

    A Dictionary of options. Can be null

    • :focus(Lang.Number)

      The index of the CheckboxMenuItem that should have initial focus. (optional)

    • :focusItemHeight(Lang.Number)

      The pixel height of the center menu item of this menu. This option is ignored on products with touch screens. (optional)

    • :title(WatchUi.Drawable)

      A Drawable that will render the title area. (optional)

    • :footer(WatchUi.Drawable)

      A Drawable that will render the area after the final item in the menu.(optional)

    • :foreground(WatchUi.Drawable)

      A Drawable to render on top of menu items. (optional)

    • :titleItemHeight(Lang.Number)

      The pixel height of the header menu item of this menu (optional)

    • :footerItemHeight(Lang.Number)

      The pixel height of the footer menu item of this menu. (optional)

    • :icon(Graphics.BitmapType, WatchUi.Drawable, Lang.ResourceId)

      the default icon for the menu incase menuitem do not have it populated

    • :theme(WatchUi.MenuTheme)

      The menu theme, or null for no theme. Defaults to MENU_THEME_DEFAULT.

    • :dividerType(Menu2.DividerType)

      The divider type, if null is passed as value, divider will be disabled (non-visible). Defaults to DIVIDER_TYPE_DEFAULT.

See Also:

Since:

API Level 3.0.0

Throws:

setBackgroundColor(color as Graphics.ColorType) as Void

Set the background color.

Parameters:

Since:

API Level 3.0.0

Throws:

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

Set or change the desired divider type.

If set to Menu2.DIVIDER_TYPE_ICON. Icon from CustomMenuItem.setDividerIcon will be rendered on the left side of the divider.

Set to null to disable divider which may also disable MenuTheme, CustomMenuItem.draw will be called with full width of menu item.

Menu2.DIVIDER_TYPE_DEFAULT will be used if not set for devices that support divider.

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.

setFooter(drawable as WatchUi.Drawable or Null) as Void

Set the footer drawable.

Parameters:

  • drawable(WatchUi.Drawable, null)

    A drawable that will render the footer area or null.

Since:

API Level 3.0.0

Throws:

setForeground(drawable as WatchUi.Drawable or Null) as Void

Set the foreground drawable.

Parameters:

  • drawable(WatchUi.Drawable, null)

    A Drawable to render on top of the menu items or null.

Since:

API Level 3.0.0

Throws:

setTitle(drawable as WatchUi.Drawable or Null) as Void

Set the title drawable.

Parameters:

  • drawable(WatchUi.Drawable, null)

    A drawable that will render the title area or null.

Since:

API Level 3.0.0

Throws:


Generated Sep 23, 2024, 3:32:49 PM