Class: Toybox.WatchUi.View
- Inherits:
-
Toybox.Lang.Object
Overview
A View is an object that represents a page within an app.
An app may have multiple View objects representing things like menus and other app states. Each View contains a Layout, which in turn contain Drawable objects, such as Bitmaps and Text. View objects also handle the life cycle of each app, which varies depending on the app type:
- Widgets and Watch Apps
-
onLayout() → onShow() → onUpdate() → onHide()
- Watch Faces
- Data Fields
-
onLayout() → onShow() → onUpdate()
If the size of the data field has changed since the last onUpdate(), onLayout() will be called prior to onUpdate(). However, onLayout(), onShow(), and onUpdate() are not called for SimpleDataField objects.
See Also:
Direct Known Subclasses
WatchUi.DataField, WatchUi.DataFieldAlert, WatchUi.GlanceView, WatchUi.MapView, WatchUi.Menu2, WatchUi.Picker, WatchUi.WatchFace
Typedef Summary collapse
- ControlBarOptions as { :leftButton as WatchUi.ControlBarLeftButton, :title as Lang.String, :rightButton as WatchUi.ControlBarRightButton }
Instance Method Summary collapse
-
addLayer(layer as WatchUi.Layer) as Void
Add a WatchUi.Layer on the top of view's layer stack.
-
clearLayers() as Void
Clear all layers that are added to the view.
-
findDrawableById(identifier as Lang.Object) as WatchUi.Drawable or Null
Find a Drawable by its ID.
-
getLayerIndex(layer as WatchUi.Layer) as Lang.Number
Return the index of the layer from the bottom of the view layer stack.
-
getLayers() as Lang.Array<WatchUi.Layer> or Null
Get a copy of the layer stack currently added to the view, sorted by the drawing order, i.e.
-
initialize()
Constructor.
-
insertLayer(layer as WatchUi.Layer, idx as Lang.Number) as Void
Insert the layer at the given index in the layer stack, this will stop animation playback.
-
onHide() as Void
Hide the View.
-
onLayout(dc as Graphics.Dc) as Void
The entry point for the View.
-
onShow() as Void
Show the View.
-
onUpdate(dc as Graphics.Dc) as Void
Update the View.
-
removeLayer(layer as WatchUi.Layer) as Lang.Boolean
Remove a layer from the view layer stack, this will stop animation playback.
-
setClockHandPosition(options as { :clockState as WatchUi.AnalogClockState, :hour as Lang.Number or Null, :minute as Lang.Number or Null }) as Lang.Boolean
Set the clock hands position.
-
setControlBar(options as View.ControlBarOptions) as Void
Set control bar options for this view.
-
setKeyToSelectableInteraction(enable as Lang.Boolean) as Void
Enter Selectable interaction mode.
-
setLayout(layout as Lang.Array<WatchUi.Drawable> or Null) as Void
Set the layout for the View.
Instance Method Details
addLayer(layer as WatchUi.Layer) as Void
Add a WatchUi.Layer on the top of view's layer stack. Users do not need to draw the layer on the screen manually, instead, once a layer is added to the view, the system will draw all layers during screen updates which include View update (e.g. onUpdate/onPartialUpdate) and animation playback.
Disabled for DataFiled and Background Apps
clearLayers() as Void
Clear all layers that are added to the view
findDrawableById(identifier as Lang.Object) as WatchUi.Drawable or Null
Find a Drawable by its ID.
A common use for this method is to get layout information to format dynamic content, such as a string that updates at runtime.
getLayerIndex(layer as WatchUi.Layer) as Lang.Number
Return the index of the layer from the bottom of the view layer stack
getLayers() as Lang.Array<WatchUi.Layer> or Null
Get a copy of the layer stack currently added to the view, sorted by the drawing order, i.e. from the bottom to the top.
initialize()
Constructor
insertLayer(layer as WatchUi.Layer, idx as Lang.Number) as Void
Insert the layer at the given index in the layer stack, this will stop animation playback.
onHide() as Void
Hide the View.
This is called before the View is removed from the foreground. This occurs when a new View object is pushed on top of the current one, when the current View is popped, or when the app is closed. Resources should be freed from memory at this point if the current View will be left on the page stack.
onLayout(dc as Graphics.Dc) as Void
The entry point for the View.
onLayout() is called before the View is shown to load resources and set up the layout of the View.
onShow() as Void
Show the View.
This is called when the View is brought into the foreground. Resources should be loaded into system memory for use in the View at this point.
onUpdate(dc as Graphics.Dc) as Void
Update the View.
This is called when a View is brought to the foreground, after the call to onShow(). While a View is active, this method is generally used to update dynamic content in the View. There are also some special cases when it will be invoked:
-
On WatchUi.requestUpdate() calls within Widgets and Watch Apps
-
Once per minute in Watch Faces when in low power mode
-
Once per second in Watch Faces when in high power mode
-
Once per second in Data Fields
-
At an increased rate while an animation is active
-
More than one call to onUpdate() may occur during View transitions
If a class that extends View does not implement this function then any Drawable objects contained in the View will automatically be drawn.
removeLayer(layer as WatchUi.Layer) as Lang.Boolean
Remove a layer from the view layer stack, this will stop animation playback.
setClockHandPosition(options as { :clockState as WatchUi.AnalogClockState, :hour as Lang.Number or Null, :minute as Lang.Number or Null }) as Lang.Boolean
Set the clock hands position.
setControlBar(options as View.ControlBarOptions) as Void
Set control bar options for this view.
Use of this method has many restrictions.
With View, the control bar can be hidden by passing null
.
If options is non-null, the :leftButton
option must be provided. All values for
CONTROL_BAR_RIGHT_BUTTON_* and
CONTROL_BAR_RIGHT_BUTTON_* are allowed.
With Menu2 and CustomMenu,
the options
parameter cannot be null
; the control bar is always shown. The
:leftButton
option must be set to CONTROL_BAR_LEFT_BUTTON_BACK.
The :rightButton
option may be null
, for no button, or
CONTROL_BAR_RIGHT_BUTTON_ACCEPT.
Attempting to call this method on any other class derived from View, or with an unsupported option for the given view type, will result in an exception.
setKeyToSelectableInteraction(enable as Lang.Boolean) as Void
Enter Selectable interaction mode.
When enabled, physical buttons may be used to cycle through on-screen Selectable objects. The first registered Selectable in the current layout will be highlighted initially.
setLayout(layout as Lang.Array<WatchUi.Drawable> or Null) as Void
Set the layout for the View.
Set the array of Drawable objects to be managed by this View. The specified Drawables will be:
-
Drawn automatically via calls to onUpdate()
-
Searched via calls to findDrawableById()