Module: Toybox::WatchUi

Overview

Note:

All keys in the key types enum listed after EXTENDED_KEYS (16) were added after ConnectIQ version 1.1.2. Before evaluating these keys, check for the availability of these keys with a has check:

if (Toybox.WatchUi has :EXTENDED_KEYS) {...}

The WatchUi module contains user interface elements available within apps.

WatchUi provides several classes that represent Views, or what is displayed on the screen of a device. Also available are UI elements like on-screen menus, progress bars, buttons, and various pickers. More abstract classes represent all drawable objects, such as bitmaps and text.

Since:

  • 1.0.0

App Types:

  • Watch Face

  • Data Field

  • Widget

  • App

  • Audio Content Provider App

  • Background Services

Defined Under Namespace

Classes: AnimationDelegate, AnimationLayer, AnimationResource, BehaviorDelegate, Bitmap, BitmapResource, Button, CheckboxMenu, CheckboxMenuItem, ClickEvent, Confirmation, ConfirmationDelegate, CustomMenu, CustomMenuItem, DataField, Drawable, FontResource, GlanceView, GlanceViewDelegate, IconMenuItem, InputDelegate, InvalidMenuItemTypeException, InvalidPointException, InvalidSelectableStateException, KeyEvent, Layer, MapMarker, MapPolyline, MapTrackView, MapView, Menu, Menu2, Menu2InputDelegate, MenuInputDelegate, MenuItem, NumberPicker, NumberPickerDelegate, Picker, PickerDelegate, PickerFactory, ProgressBar, Selectable, SelectableEvent, SimpleDataField, SwipeEvent, Text, TextArea, TextPicker, TextPickerDelegate, ToggleMenuItem, View, WatchFace, WatchFaceDelegate, WatchFacePowerInfo

Constant Summary

KEY_POWER = 0

The power key

Since:

  • 1.0.0

KEY_LIGHT = 1

The light key

Since:

  • 1.0.0

KEY_ZIN = 2

The zoom in key

Since:

  • 1.0.0

KEY_ZOUT = 3

The zoom out key

Since:

  • 1.0.0

KEY_ENTER = 4

The enter key

Since:

  • 1.0.0

KEY_ESC = 5

The escape key

Since:

  • 1.0.0

KEY_FIND = 6

The find key

Since:

  • 1.0.0

KEY_MENU = 7

The menu key

Since:

  • 1.0.0

KEY_DOWN = 8

The down key

Since:

  • 1.0.0

KEY_DOWN_LEFT = 9

The down left key

Since:

  • 1.0.0

KEY_DOWN_RIGHT = 10

The down key

Since:

  • 1.0.0

KEY_LEFT = 11

The left key

Since:

  • 1.0.0

KEY_RIGHT = 12

The right key

Since:

  • 1.0.0

KEY_UP = 13

The up key

Since:

  • 1.0.0

KEY_UP_LEFT = 14

The up-left

Since:

  • 1.0.0

KEY_UP_RIGHT = 15

The up-right key

Since:

  • 1.0.0

EXTENDED_KEYS = 16

Indicates extended key support

Since:

  • 1.1.2

KEY_PAGE = 17

The page key

Since:

  • 1.1.2

KEY_START = 18

The start key

Since:

  • 1.1.2

KEY_LAP = 19

The lap key

Since:

  • 1.1.2

KEY_RESET = 20

The reset key

Since:

  • 1.1.2

KEY_SPORT = 21

The sport key

Since:

  • 1.1.2

KEY_CLOCK = 22

The clock key

Since:

  • 1.1.2

KEY_MODE = 23

The mode key

Since:

  • 1.1.2

ANIM_TYPE_LINEAR = 0

Animation with a constant speed

Since:

  • 1.0.0

ANIM_TYPE_EASE_IN = 1

Animation that increases in speed from start to end

Since:

  • 1.0.0

ANIM_TYPE_EASE_OUT = 2

Animation that decreases in speed from start to end

Since:

  • 1.0.0

ANIM_TYPE_EASE_IN_OUT = 3

Animation that increases in speed from the start, then decreases in speed toward the end

Since:

  • 1.0.0

PRESS_TYPE_DOWN = 0

The key is pressed down

Since:

  • 1.1.2

PRESS_TYPE_UP = 1

The key is released

Since:

  • 1.1.2

PRESS_TYPE_ACTION = 2

The key's action is performed

Since:

  • 1.1.2

CLICK_TYPE_TAP = 0

A tap on the screen

Since:

  • 1.0.0

CLICK_TYPE_HOLD = 1

A press and hold on the screen

Since:

  • 1.0.0

CLICK_TYPE_RELEASE = 2

A release of a hold on the screen

Since:

  • 1.0.0

MAP_MARKER_ICON_PIN = 0

The default Garmin map marker pin icon

Since:

  • 3.0.0

MAP_MODE_PREVIEW = 0

The preview mode for a MapView

Since:

  • 3.0.0

MAP_MODE_BROWSE = 1

The browse mode for a MapView

Since:

  • 3.0.0

SWIPE_UP = 0

A swipe in the upward direction

Since:

  • 1.0.0

SWIPE_RIGHT = 1

A swipe towards the right

Since:

  • 1.0.0

SWIPE_DOWN = 2

A swipe in the downward direction

Since:

  • 1.0.0

SWIPE_LEFT = 3

A swipe towards the left

Since:

  • 1.0.0

CONFIRM_NO = 0

Since:

  • 1.0.0

CONFIRM_YES = 1

Since:

  • 1.0.0

NUMBER_PICKER_DISTANCE = 0

A Float in meters (m)

Since:

  • 1.0.0

NUMBER_PICKER_TIME = 1

A Duration

Since:

  • 1.0.0

NUMBER_PICKER_TIME_MIN_SEC = 2

A Duration

Since:

  • 1.0.0

NUMBER_PICKER_TIME_OF_DAY = 3

A Duration representing the number of seconds since midnight

Since:

  • 1.0.0

NUMBER_PICKER_WEIGHT = 4

A Float in kilograms (kg)

Since:

  • 1.0.0

NUMBER_PICKER_HEIGHT = 5

A Float in meters (m)

Since:

  • 1.0.0

NUMBER_PICKER_CALORIES = 6

A Number

Since:

  • 1.0.0

NUMBER_PICKER_BIRTH_YEAR = 7

A Number

Since:

  • 1.0.0

SLIDE_IMMEDIATE = 0

No transition.

Since:

  • 1.0.0

SLIDE_LEFT = 1

The View slides to the left.

Since:

  • 1.0.0

SLIDE_RIGHT = 2

The View slides to the right.

Since:

  • 1.0.0

SLIDE_DOWN = 3

The View slides down.

Since:

  • 1.0.0

SLIDE_UP = 4

The View slides up.

Since:

  • 1.0.0

LAYOUT_VALIGN_TOP = -0x7FFFFFFF

Set a Drawable object's locY property to this to align it to the top edge of the device context (Dc).

Since:

  • 1.2.0

LAYOUT_VALIGN_BOTTOM = -0x7FFFFFFE

Set a Drawable object's locY property to this to align it to the bottom edge of the device context (Dc).

Since:

  • 1.2.0

LAYOUT_VALIGN_CENTER = -0x7FFFFFFD

Set a Drawable object's locY property to this to center it vertically in the device context (Dc).

Since:

  • 1.2.0

LAYOUT_VALIGN_START = -0x7FFFFFFC

Set a Drawable object's locY property to this to make it equal to its parent's locY property.

Since:

  • 1.2.0

LAYOUT_HALIGN_LEFT = -0x7FFFFFFF

Set a Drawable object's locX property to this to align it along the left edge of the device context (Dc).

Since:

  • 1.2.0

LAYOUT_HALIGN_RIGHT = -0x7FFFFFFE

Set a Drawable object's locX property to this to align it along the right edge of the device context (Dc).

Since:

  • 1.2.0

LAYOUT_HALIGN_CENTER = -0x7FFFFFFD

Set a Drawable object's locX property to this to center it horizontally in the device context (Dc).

Since:

  • 1.2.0

LAYOUT_HALIGN_START = -0x7FFFFFFC

Set a Drawable object's locX property to this to make it equal to its parent's locX property.

Since:

  • 1.2.0

ANIMATION_EVENT_COMPLETE = 0

Since:

  • 1.0.0

ANIMATION_EVENT_CANCELED = 1

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

animate(object, property, type, start, stop, period, callback) ⇒ Object

Animate an Object.

Animate works by changing an object property over time, such as the x-position of a Drawable. The animation starts after the call and runs the length of the specified period. During this time, the View object's onUpdate() method will be invoked at an increased rate to facilitate animation.

Examples:

Move a bitmap across the screen from left to right

using System.WatchUi;

square = new Ui.Bitmap({
    :rezId=>Rez.Drawables.square,
    :locX=>10,
    :locY=>30
});
WatchUi.animate(square, :locX, Ui.ANIM_TYPE_LINEAR, 10, 200, 10, null);

Parameters:

See Also:

Since:

  • 1.0.0


13213
13214
# File 'Monkeybrains.rb', line 13213

def animate(object, property, type, start, stop, period, callback)
end

loadResource(resource) ⇒ Toybox::WatchUi::FontResource, ...

Load a resource from the executable. defined in the project's resources.xml file

Examples:

Loading a Bitmap resource

// The resources.xml file contents:
// <resources>
//     <string id="AppName">APEELingApp</string>
//     <bitmap id="banana" filename="images/banana.png" />
// </resources>
using Toybox.WatchUi;

banana = new WatchUi.Bitmap({
    :rezId=>Rez.Drawables.banana,
    :locX=>10,
    :locY=>10
});

Parameters:

Returns:

Since:

  • 1.0.0


13234
13235
# File 'Monkeybrains.rb', line 13234

def loadResource(resource)
end

popView(transition) ⇒ Object

Pop the current View from the View stack.

Parameters:

Since:

  • 1.0.0


15352
15353
# File 'Monkeybrains.rb', line 15352

def popView(transition)
end

pushView(view, delegate, transition) ⇒ Object

Push a View onto the View stack.


15345
15346
# File 'Monkeybrains.rb', line 15345

def pushView(view, delegate, transition)
end

requestUpdateObject

Request a call to the onUpdate() method for the current View.

See Also:

Since:

  • 1.0.0


14098
14099
# File 'Monkeybrains.rb', line 14098

def requestUpdate()
end

switchToView(view, delegate, transition) ⇒ Object

Pop the current View from the View stack and push a new one.

This method only supports switching to user-defined View objects, so will only accept InputDelegate or BehaviorDelegate objects as delegates for the pushed View.

Parameters:

Since:

  • 1.0.0


15367
15368
# File 'Monkeybrains.rb', line 15367

def switchToView(view, delegate, transition)
end