Skip to main content
Shapes and lays out styled runs of text with the runtime’s shaper, so scripts get real line breaking and bidirectional ordering. Append runs, set the box, then draw it in one call or walk its lines and glyphs to draw them yourself. Codepoint indices are 1 based like utf8.offset.

Fields

sizing

overflow

align

wrap

wordBreak

origin

direction

maxWidth

Wrap width when sizing is not ‘autoWidth’.

maxHeight

Height the text overflows at when sizing is ‘fixed’.

paragraphSpacing

Space between paragraphs separated by a newline.

length

Number of codepoints appended.

isEmpty

lineCount

Constructors

new

Creates an empty text.

Methods

append

Appends a styled run. Runs join into one string; a newline starts a paragraph.

clear

Removes every run.

draw

Draws every run with its own paint, or all of them with the given paint.

bounds

Minimum and maximum corner of the laid out text.

line

The line at a 1 based index, top to bottom.

lines

Every line, top to bottom.

hitTest

The codepoint index nearest a point in the text’s local space.

caret

The caret before the codepoint at index: its x, top and bottom. Nil when the text is empty.

selectionRects

Rectangles covering the codepoints from one index to another, one per glyph.