M MY Multiplayer: Wiki
Side
Kind

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

NameTypeDescription
textstringThe text.
widthfloatAvailable width in pixels, used with wordBreak.default 0
scaleX, scaleYfloatText scale. One number applies to both axes. A vec2 also works.default 1
fontstring|elementA font's name (from a pack or given to dxCreateFont) or a font element from dxCreateFont.default default
wordBreakboolWrap lines that do not fit in width.default false
colorCodedboolLeave #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)

See also