gre.get_string_size
gre.get_string_size(
font,
font_size,
str,
width,
data
)
Calculate the area in pixels which the given string will occupy on the screen.
This call can only be made from the main Lua action execution thread.
Parameters
| Parameter | Type | Description |
|---|---|---|
font | #string | The name of the font to render |
font_size | #number | The size of the font to render |
str | #string | The string to render |
width | #number | A clipping width (in pixels) for the string, used to calculate how many characters fit |
data | #table | A table containing additional options. Valid |
Set String Size Options
| Key | Type | Description |
|---|---|---|
length | #number | The number of characters to process. |
spacing | #number | The letter spacing text render extension property. |
wrapping | #boolean | A boolean to activate wrapping logic |
Returns
A #table with the following:
| Key | Type | Description |
|---|---|---|
width | #number | The width of the widest line in the body of text. |
height | #number | The total height of the wrapped text in pixels. |
n_lines | #number | The number of lines the text fills when wrapped. |
Example
local t = gre.get_string_size('fonts/Roboto-ThinItalic.ttf', 72, 'How long is this string?', 600, {["wrapping"] = true} )