Txt

From Sim Innovations Wiki
Jump to navigation Jump to search

Description

_txt(text, style, x, y)
_txt(text, style, x, y, opacity)

_txt is used to draw text within a canvas.

Info This function may only be called within a canvas draw callback


Info If you like to display static text, consider using txt_add instead

Return value

This function won't return any value.

Arguments

# Argument Type Description
1 txt String This is the txt being shown
2 style String The style to use. See the paragraph below for available style arguments.
3 x Number This is the most left point of the canvas where your text should be shown.
4 y Number This is the most top point of the canvas where your text should be shown.
5 opacity Number (Optional) The opacity in which the text should be drawn. Ranges from 0.0 (invisible) to 1.0 (completely visible).

Style

Argument Type Description
font String The TTF font file name (searched in the resource folder of the instrument)
size Number The font size (in px)
color String The color, can be color string like "red", "blue", "cyan", etc. etc. Can also be a hex value, "#FFFFFF"
halign String The horizontal alignment of the text. Can be "left", "center" or "right".

Included fonts

Font File name (used in style) Example Version
Arimo Regular arimo_regular.ttf example AM 3.6/AP 3.6 and up
Arimo Bold arimo_bold.ttf example AM 3.6/AP 3.6 and up
Digital 7 digital-7-mono.ttf example AM 3.0/AP 3.0 and up
Inconsolata Regular inconsolata_regular.ttf example AM 3.6/AP 3.6 and up
Inconsolata Bold inconsolata_bold.ttf example AM 3.6/AP 3.6 and up
Roboto Regular roboto_regular.ttf example AM 3.0/AP 3.0 and up
Roboto Bold roboto_bold.ttf example AM 3.0/AP 3.0 and up

Example

canvas_id = canvas_add(0, 0, 200, 200, function()
  _txt("Hello world", "font:roboto_bold.ttf; size:16; color: green; halign:left;", 0, 0)
end)