dxGetTextSize
Client
Measures the width and height a text takes on the screen.
float, float|false dxGetTextSize(string text [, float width = 0, float scaleX, scaleY = 1, string|element font = default, bool wordBreak = false, bool colorCoded = false])
Parameters
| Name | Type | Description |
|---|---|---|
| text | string | The text. |
| width | float | Available width in pixels, used with wordBreak.default 0 |
| scaleX, scaleY | float | Text scale. One number applies to both axes. A vec2 also works.default 1 |
| font | string|element | A font's name (from a pack or given to dxCreateFont) or a font element from dxCreateFont.default default |
| wordBreak | bool | Wrap lines that do not fit in width.default false |
| colorCoded | bool | Leave #RRGGBB colour codes out of the measure.default false |
Returns
The width and height in pixels, or false when the font does not exist.
Example
local text = "A long description that has to wrap over several lines."
local w, h = dxGetTextSize(text, 300, 1, "default", true)
addEventHandler("onClientRender", root, function()
dxDrawRectangle(20, 20, w + 20, h + 20, tocolor(0, 0, 0, 160))
dxDrawText(text, 30, 30, 330, 30 + h, tocolor(255, 255, 255), 1, "default", "left", "top", false, true)
end)