natiny.font.measure_wrapped

Lua
natiny.font.measure_wrapped(font, text [, max_width]) -> width, height, lines

Lays text out and reports the size of the block it makes, without drawing it.

Parameters

Name Type Default Description
font number Font handle from natiny.font.create
text string UTF-8 text to lay out
max_width number 0 Wrap width in drawing units; values at or below 0 do not wrap

Returns

Type Description
number Width of the widest line in drawing units
number Height of the block in drawing units
number Number of lines in the block

Example

Lua
local w, h, lines = natiny.font.measure_wrapped(font, message, 300)

-- a panel that fits its text
natiny.render.set_color(natiny.color.from_hex("#1A1A1F"))
natiny.render.rectangle(20, 20, w + 16, h + 16)
natiny.render.set_color(natiny.color.from_hex("#FFFFFF"))
natiny.render.text_box(font, 28, 28, 300, h, message)

Notes

  • Lines break at spaces and tabs, at \n, and between Han, kana and Hangul characters, which are written without spaces. A word longer than max_width is cut where it stops fitting rather than allowed to overflow.