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.
Classes Under Namespace
Classes: BitmapReference, BitmapTexture, BoundingBox, BufferedBitmap, BufferedBitmapReference, Dc, FontReference, InvalidBitmapResourceException, InvalidPaletteException, ResourceReference
Constant Summary
-
FontDefinition
-
ColorValue
-
TextJustification
-
BlendMode
-
AlphaBlending
-
ArcDirection
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 |
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 |
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
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
Name | Value | Since | Description |
---|---|---|---|
ALPHA_BLENDING_FULL | 0 | API Level 4.0.0 |
Default surface for buffered bitmap with maximum alpha blending support |
ALPHA_BLENDING_PARTIAL | 1 | API Level 4.0.0 |
Surface for buffered bitmap with at least a 1-bit alpha channel. The actual number of bits may vary by device. |
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 WatchUi.BitmapResource or Graphics.BufferedBitmap or Graphics.BitmapReference or Graphics.BufferedBitmapReference
-
typedef ColorType as Lang.Number or Graphics.ColorValue
-
typedef FontType as WatchUi.FontResource or Graphics.FontDefinition or Graphics.FontReference
Instance Method Summary collapse
-
createBufferedBitmap(options as { :width as Lang.Number, :height as Lang.Number, :palette as Lang.Array<Graphics.ColorType>, :colorDepth as Lang.Number, :bitmapResource as WatchUi.BitmapResource or Graphics.BitmapReference, :alphaBlending as Graphics.AlphaBlending }) as Graphics.BufferedBitmapReference
Create a buffered bitmap object.
-
createColor(alpha as Lang.Number, red as Lang.Number, green as Lang.Number, blue as Lang.Number) as Lang.Number
Create a color with the individual channel values passed in.
-
fitTextToArea(text as Lang.String, font as Graphics.FontType, width as Lang.Number, height as Lang.Number, truncate as Lang.Boolean) as Lang.String or Null
Get a text string to fit in a specified area.
-
getFontAscent(font as Graphics.FontType) as Lang.Number
Get the recommended distance above the baseline for single spaced text.
-
getFontDescent(font as Graphics.FontType) as Lang.Number
Get the recommended distance below the baseline for single spaced text.
-
getFontHeight(font as Graphics.FontType) as Lang.Number
Get the height (ascent plus descent) of the given font.
Instance Method Details
createBufferedBitmap(options as { :width as Lang.Number, :height as Lang.Number, :palette as Lang.Array<Graphics.ColorType>, :colorDepth as Lang.Number, :bitmapResource as WatchUi.BitmapResource or Graphics.BitmapReference, :alphaBlending as Graphics.AlphaBlending }) as Graphics.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.
The result of a draw/fill operation to a BufferedBitmap created with ALPHA_BLENDING_PARTIAL may produce inconsistent results between devices and the ConnectIQ simulator if the drawn pixels are not fully opaque or fully transparent.
createColor(alpha as Lang.Number, red as Lang.Number, green as Lang.Number, blue as Lang.Number) as Lang.Number
Create a color with the individual channel values passed in
fitTextToArea(text as Lang.String, font as Graphics.FontType, width as Lang.Number, height as Lang.Number, truncate as Lang.Boolean) as Lang.String or Null
Get a text string to fit in a specified area
FontReference is only supported in CIQ 4.0.0 and later
getFontAscent(font as Graphics.FontType) as Lang.Number
Get the recommended distance above the baseline for single spaced text.
The base line is the line on which the text sits.
FontReference is only supported in CIQ 4.0.0 and later
getFontDescent(font as Graphics.FontType) as Lang.Number
Get the recommended distance below the baseline for single spaced text.
The base line is the line on which the text sits.
FontReference is only supported in CIQ 4.0.0 and later
getFontHeight(font as Graphics.FontType) as Lang.Number
Get the height (ascent plus descent) of the given font.
FontReference is only supported in CIQ 4.0.0 and later