Class: Toybox.WatchUi.Drawable

Inherits:
Toybox.Lang.Object show all

Overview

Drawable is the base class of a drawable object.

A Drawable can be constructed using the resource compiler and loaded through the resource (Rez) module.

Example:

Using a Drawable defined as a resource

// The drawable.xml file contents:
// <drawable-list id="shapes" background="Graphics.COLOR_TRANSPARENT">
//     <shape type="circle" x="78" y="160" radius="8" color="Graphics.COLOR_RED" />
//     <shape type="rectangle" x="51" y="137" width="76" height="20" color="Graphics.COLOR_BLUE" />
// </drawable-list>

using Toybox.Graphics;
using Toybox.WatchUi;

class MyDrawableView extends WatchUi.View {
    var myShapes;

    function initialize() {
        View.initialize();
        myShapes = new Rez.Drawables.shapes();
    }

    function onUpdate(dc) {
        dc.setColor(
            Graphics.COLOR_WHITE,
            Graphics.COLOR_BLACK
        );
        dc.fillRectangle(
            0,
            0,
            dc.getWidth(),
            dc.getHeight()
        );
        myShapes.draw(dc);
    }
}

Since:

API Level 1.0.0

Direct Known Subclasses

WatchUi.Bitmap, WatchUi.Selectable, WatchUi.Text, WatchUi.TextArea

Instance Member Summary collapse

Instance Method Summary collapse

Instance Attribute Details

var height as Lang.Numeric

The clip height of the Drawable object.

Since:

API Level 1.0.0

Returns:

var identifier as Lang.Object or Null

The ID used to identify the Drawable object.

Since:

API Level 1.0.0

Returns:

var isVisible as Lang.Boolean

The visibility of the Drawable object.

Since:

API Level 3.3.0

Returns:

var locX as Lang.Numeric

The absolute, on-screen x-coordinate of the Drawable object.

Since:

API Level 1.0.0

Returns:

var locY as Lang.Numeric

The absolute, on-screen y-coordinate of the Drawable object.

Since:

API Level 1.0.0

Returns:

var width as Lang.Numeric

The clip width of the Drawable object.

Since:

API Level 1.0.0

Returns:

Instance Method Details

draw(dc as Graphics.Dc) as Void

Draw an object to the device context (Dc).

This method assumes that the device context has already been configured to the proper options.

Derived classes should check the isVisible property, if it exists, before trying to draw.

Parameters:

Since:

API Level 1.0.0

initialize(options as { :identifier as Lang.Object, :locX as Lang.Numeric, :locY as Lang.Numeric, :width as Lang.Numeric, :height as Lang.Numeric, :visible as Lang.Boolean })

Constructor

Note:

The option :visible is only supported with ConnectIQ 3.3.0 and later.

Parameters:

  • options(Lang.Dictionary)

    A Dictionary containing options for the Drawable object

    • :identifier(Lang.Object)

      The identifier for the Drawable object

    • :locX(Lang.Number)

      The absolute, on-screen x-coordinate for the Drawable object

    • :locY(Lang.Number)

      The absolute, on-screen y-coordinate for the Drawable object

    • :width(Lang.Number)

      The clip width of the Drawable object

    • :height(Lang.Number)

      The clip height of the Drawable object

    • :visible(Lang.Boolean)

      The visibility of the Drawable object

Since:

API Level 1.0.0

setLocation(x as Lang.Numeric, y as Lang.Numeric) as Void

Set the on-screen location for a Drawable object.

Parameters:

  • x(Lang.Number)

    The horizontal position on the screen

  • y(Lang.Number)

    The vertical position on the screen

Since:

API Level 1.0.0

setSize(w as Lang.Numeric, h as Lang.Numeric) as Void

Set the size of a Drawable object.

Parameters:

  • w(Lang.Number)

    The width of the Drawable object

  • h(Lang.Number)

    The height of the Drawable object

Since:

API Level 1.0.0

setVisible(visible as Lang.Boolean) as Void

Set the visibility of a Drawable object.

Parameters:

  • visible(Lang.Boolean)

    The visibility of the Drawable object

Since:

API Level 3.3.0


Generated Apr 17, 2024 9:40:39 AM