Module: Toybox.Graphics

Overview

The Graphics module provides a set of tools that allow developers to use basic drawing functionality.

This provides the ability to draw shapes, lines, fill shapes, and use dynamic layouts for graphic elements based on specific device contexts. The Device Context (Dc) is useful for developers who are interested in creating content for multiple device platforms with differing screen shapes, sizes, and color palettes.

Since:

API Level 1.0.0

App Types:

  • Watch App

  • Audio Content Provider

  • Data Field

  • Watch Face

  • Widget

Classes Under Namespace

Classes: BitmapReference, BitmapTexture, BoundingBox, BufferedBitmap, BufferedBitmapReference, Dc, FontReference, InvalidBitmapResourceException, InvalidPaletteException, ResourceReference

Constant Summary

FontDefinition

Name Value Since Description
FONT_XTINY 0

API Level 1.0.0

Extra tiny Connect IQ font

FONT_TINY 1

API Level 1.0.0

Tiny Connect IQ font

FONT_SMALL 2

API Level 1.0.0

Small Connect IQ font

FONT_MEDIUM 3

API Level 1.0.0

Medium Connect IQ font

FONT_LARGE 4

API Level 1.0.0

Large Connect IQ font

FONT_NUMBER_MILD 5

API Level 1.0.0

Normal size number only Connect IQ font

FONT_NUMBER_MEDIUM 6

API Level 1.0.0

Medium size number only Connect IQ font

FONT_NUMBER_HOT 7

API Level 1.0.0

Large size number only Connect IQ font

FONT_NUMBER_THAI_HOT 8

API Level 1.0.0

Huge size number only Connect IQ font

FONT_SYSTEM_XTINY 9

API Level 1.3.0

Extra tiny system font

FONT_SYSTEM_TINY 10

API Level 1.3.0

Tiny system font

FONT_SYSTEM_SMALL 11

API Level 1.3.0

Small system font

FONT_SYSTEM_MEDIUM 12

API Level 1.3.0

Medium system font

FONT_SYSTEM_LARGE 13

API Level 1.3.0

Large system font

FONT_SYSTEM_NUMBER_MILD 14

API Level 1.3.0

Normal size number only system font

FONT_SYSTEM_NUMBER_MEDIUM 15

API Level 1.3.0

Medium size number only system font

FONT_SYSTEM_NUMBER_HOT 16

API Level 1.3.0

Large size number only system font

FONT_SYSTEM_NUMBER_THAI_HOT 17

API Level 1.3.0

Huge size number only system font

FONT_GLANCE 18

API Level 3.1.8

Glance text font

FONT_GLANCE_NUMBER 19

API Level 3.1.8

Glance number only font

ColorValue

Name Value Since Description
COLOR_WHITE 0xFFFFFF

API Level 1.0.0

White

COLOR_LT_GRAY 0xAAAAAA

API Level 1.0.0

Light Gray

COLOR_DK_GRAY 0x555555

API Level 1.0.0

Dark Gray

COLOR_BLACK 0x000000

API Level 1.0.0

Black

COLOR_RED 0xFF0000

API Level 1.0.0

Red

COLOR_DK_RED 0xAA0000

API Level 1.0.0

Dark Red

COLOR_ORANGE 0xFF5500

API Level 1.0.0

Orange

COLOR_YELLOW 0xFFAA00

API Level 1.0.0

Yellow

COLOR_GREEN 0x00FF00

API Level 1.0.0

Green

COLOR_DK_GREEN 0x00AA00

API Level 1.0.0

Dark Green

COLOR_BLUE 0x00AAFF

API Level 1.0.0

Blue

COLOR_DK_BLUE 0x0000FF

API Level 1.0.0

Dark Blue

COLOR_PURPLE 0xAA00FF

API Level 1.0.0

Purple. Not valid on fenix 3 or D2 Bravo. Use 0x5500AA instead.

COLOR_PINK 0xFF00FF

API Level 1.0.0

Pink

COLOR_TRANSPARENT -1

API Level 1.0.0

Transparent

TextJustification

Name Value Since Description
TEXT_JUSTIFY_RIGHT 0

API Level 1.0.0

Right justify the text at the x/y coordinates

TEXT_JUSTIFY_CENTER 1

API Level 1.0.0

Center justify the text at the x/y coordinates

TEXT_JUSTIFY_LEFT 2

API Level 1.0.0

Left justify the text at the x/y coordinates

TEXT_JUSTIFY_VCENTER 4

API Level 1.0.0

Center the text vertically

Constant representing the blending mode

Since:

API Level 4.0.0

Name Value Since Description
BLEND_MODE_DEFAULT 0

API Level 4.0.0

Default blend mode for Dc drawing

BLEND_MODE_NO_BLEND 1

API Level 4.0.0

No blending mode for Dc drawing

Constant representing alpha blending state for buffered bitmaps

Since:

API Level 4.0.0

Name Value Since Description
ALPHA_BLENDING_FULL 0

API Level 4.0.0

Default surface for buffered bitmap with full alpha blending support

ALPHA_BLENDING_PARTIAL 1

API Level 4.0.0

Surface for buffered bitmap with 1-bit alpha channel

ArcDirection

Name Value Since Description
ARC_COUNTER_CLOCKWISE 0

API Level 1.2.0

Counter clockwise draw

ARC_CLOCKWISE 1

API Level 1.2.0

Clockwise draw

Typedef Summary

typedef BitmapType as BitmapResource or BufferedBitmap or BitmapReference or BufferedBitmapReference

typedef ColorType as Number or ColorValue

typedef FontType as FontResource or FontDefinition or FontReference

Instance Method Summary collapse

Instance Method Details

createBufferedBitmap(options as { :width as Number, :height as Number, :palette as Array<ColorType>, :colorDepth as Number, :bitmapResource as BitmapResource, :alphaBlending as AlphaBlending }) as BufferedBitmapReference

Create a buffered bitmap object. This function will return a Toybox::Graphics::BufferedBitmapReference object which can be used to reference the Toybox::Graphics::BufferedBitmap object.

Parameters:

  • options(Dictionary)

    Dictionary of options. Must contain width and height, with optional palette, or a BitmapResource. This resource is not allowed to have an alpha channel.

    • :width(Number)

      The width of the surface in pixels

    • :height(Number)

      The height of the surface in pixels

    • :palette(Array)

      The colors used in this surface. Using less will reduce the bitmap size. The bitmap will use the system default if not provided. The maximum palette size allowed is 256 colors. If a palette is provided, the number of colors must also be <= to the number of system colors.

    • :colorDepth(Number)

      Color depth in terms of bits/pixel, when missing, default to system value.

    • :bitmapResource(BitmapResource)

      A BitmapResource to initialize

    • :alphaBlending(Number)

      A AlphaBlending enum to specify the level of alpha blending support for this buffered bitmap object

Returns:

Since:

API Level 4.0.0

Throws:

createColor(alpha as Number, red as Number, green as Number, blue as Number) as Number

Create a color with the individual channel values passed in

Parameters:

  • alpha(Number)

    Number value ranging from 0-255 representing alpha channel

  • red(Number)

    Number value ranging from 0-255 representing red channel

  • green(Number)

    Number value ranging from 0-255 representing green channel

  • blue(Number)

    Number value ranging from 0-255 representing blue channel

Returns:

  • color [Toybox::Lang::Number] 32-bit value representing the created color that can be used with Toybox.Graphics functions.

Since:

API Level 4.0.0

fitTextToArea(text as String, font as FontType, width as Number, height as Number, truncate as Boolean) as String or Null

Get a text string to fit in a specified area

Note:

FontReference is only supported in CIQ 4.0.0 and later

Parameters:

  • text(String)

    The text to fit into the given area, which may include newlines

  • font(FontDefinition, FontReference)

    The font to use when determining line break placement

  • width(Number)

    The width of the area to fit within

  • height(Number)

    The height of the area to fit within

  • truncate(Boolean)

    If true, the resulting string may be truncated to fit within the provided area using the provided font

Returns:

  • Returns a String suitable for display in the given area. The String will be truncated if the 'truncate' parameter is true and the String cannot fit into the specified area. Otherwise, null will be returned.

Since:

API Level 3.1.0

getFontAscent(font as FontType) as Number

Get the recommended distance above the baseline for single spaced text.

The base line is the line on which the text sits.

Note:

FontReference is only supported in CIQ 4.0.0 and later

Parameters:

Returns:

  • Number

    The ascent of the font

Since:

API Level 1.2.0

getFontDescent(font as FontType) as Number

Get the recommended distance below the baseline for single spaced text.

The base line is the line on which the text sits.

Note:

FontReference is only supported in CIQ 4.0.0 and later

Parameters:

Returns:

  • Number

    The descent of the font

Since:

API Level 1.2.0

getFontHeight(font as FontType) as Number

Get the height (ascent plus descent) of the given font.

Note:

FontReference is only supported in CIQ 4.0.0 and later

Parameters:

Returns:

  • Number

    The height of the font

Since:

API Level 1.2.0


Generated Apr 22, 2021 10:10:32 AM