Class “Canvas”

Object > NativeObject > Widget > Composite > Canvas

Canvas is a widget that can be used to draw graphics using a canvas context.

Canvas on Android
Android
Canvas on iOS
iOS
Constructor public
Singleton No
Namespace tabris
Direct subclasses None
JSX support Element: <Canvas/>
Parent element: <Composite/> and any widget extending Composite
Child elements: Widgets
Text content: Not supported

Example

import {Canvas, contentView} from 'tabris';

new Canvas({layoutData: 'fill'})
  .onResize(({target: canvas, width, height}) => {
    let context = canvas.getContext("2d", width, height);
    context.moveTo(0, 0);
    // ...
  }).appendTo(contentView);

See also:

Constructor

new Canvas(properties?)

Parameter Type Optional Description
properties Properties<Canvas> Yes Sets all key-value pairs in the properties object as widget properties.

Methods

getContext(contextType, width, height)

Returns the drawing context with the given size.

Parameter Type Optional Description
contextType string No The context identifier. Only "2d" is supported.
width number No the width of the canvas context to create
height number No the height of the canvas context to create

Returns CanvasContext