Interface TextLayerOptions

Options for TextLayer. Required properties are always initialised with defaults by the TextLayer constructor.

interface TextLayerOptions {
    width?: number;
    height?: number;
    position?: LayerPosition;
    visible: boolean;
    opacity: number;
    renderers: RendererEntry[];
    backgroundColor?: string;
    backgroundOpacity?: number;
    borderColor?: string;
    borderWidth?: number;
    top?: string | number;
    left?: string | number;
    color: string;
    fontSize: string | number;
    fontUnit: string;
    fontFamily: string;
    fontStyle: string;
    textBaseline: CanvasTextBaseline;
    hOffset: number;
    vOffset: number;
    strokeWidth: number;
    strokeColor: string;
    adjustWidth: boolean;
    adjustDirection?: "both" | "shrink" | "expand";
    outlineWidth: number;
    outlineColor: string;
    antialiasing: boolean;
    text?: string;
    hAlign?: HAlign;
    vAlign?: VAlign;
}

Hierarchy (view full)

Properties

width?: number

Layer canvas width in pixels. Defaults to DMD width.

height?: number

Layer canvas height in pixels. Defaults to DMD height.

position?: LayerPosition

Layer position within the DMD frame.

visible: boolean

Whether the layer is visible. Default: true.

opacity: number

Layer opacity between 0 (transparent) and 1 (opaque). Default: 1.

renderers: RendererEntry[]

Renderers to register (and optionally activate) on this layer. Each entry is either a RendererInstanceEntry (pre-created instance) or a RendererClassEntry (class instantiated by the layer with the correct dimensions). Set active: false to register without activating. Default: [].

backgroundColor?: string

Background fill color drawn behind the layer content. Transparent if omitted.

backgroundOpacity?: number

Background fill opacity 0–1. Default: 1.

borderColor?: string

Border stroke color drawn around the layer edge. No border if omitted.

borderWidth?: number

Border stroke width in pixels. Default: 0.

top?: string | number

Top position of the text within the layer, in pixels or as a percentage string (e.g. '50%'). Overrides vAlign when set. The value is the y passed to fillText, so textBaseline decides what it anchors (with the default 'top' baseline, the top of the em square - which sits slightly above the glyph ink). Unset by default, so vAlign places the text.

left?: string | number

Left position of the text within the layer, in pixels or as a percentage string (e.g. '50%'). Overrides hAlign when set. Unset by default, so hAlign places the text.

color: string

Text fill colour. Default: Colors.White.

fontSize: string | number

Font size value. Default: '10'.

fontUnit: string

Font size unit (e.g. '%', 'px'). Default: '%'.

fontFamily: string

Font family name. Default: 'Arial'.

fontStyle: string

Font style (e.g. 'normal', 'italic'). Default: 'normal'.

textBaseline: CanvasTextBaseline

Canvas text baseline. Default: 'top'.

hOffset: number

Horizontal pixel offset. Default: 0.

vOffset: number

Vertical pixel offset. Default: 0.

strokeWidth: number

Stroke width in pixels. Default: 0.

strokeColor: string

Stroke colour. Default: Colors.Black.

adjustWidth: boolean

Shrink font until text fits the layer width. Default: false.

adjustDirection?: "both" | "shrink" | "expand"

Controls how the adjustWidth-computed size can change across setText() calls:

  • 'both': recompute freely each time - size can grow or shrink between calls.
  • 'shrink': size only ever shrinks across calls - a later, narrower text won't grow it back above a previous, wider text's shrunk size.
  • 'expand': size only ever grows across calls - a later, wider text won't shrink it below a previous size (may overflow instead). Default: 'both'.
outlineWidth: number

Outline width in pixels. Default: 0.

outlineColor: string

Outline colour. Default: Colors.Black.

antialiasing: boolean

Enable sub-pixel antialiasing. Default: true.

text?: string

Text content.

hAlign?: HAlign

Horizontal alignment of the text within the layer. Ignored when left is set. Default: 'center'.

vAlign?: VAlign

Vertical alignment of the text within the layer. Ignored when top is set. Default: 'middle'.