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.Symbol, :titleItemHeight as Lang.Number or Null, :footerItemHeight as Lang.Number or Null, :theme as WatchUi.MenuTheme 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.

Parameters:

  • itemHeight(Lang.Number)

    The pixel height of menu items rendered by this menu.

  • backgroundColor(Lang.Number)

    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.Symbol)

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

    • :theme(Lang.Number)

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

Since:

API Level 3.0.0

Throws:

setBackgroundColor(color as Graphics.ColorType) as Void

Set the background color.

Parameters:

  • color(Lang.Number)

    The color to fill the background of the menu with.

Since:

API Level 3.0.0

Throws:

setFooter(drawable as WatchUi.Drawable) 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) 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 Mar 18, 2024 2:40:15 PM