- Documentation
- Client functions
- dxGetTextWidth
Function
dxGetTextWidth
Returns the width of text in pixels for a given scale and font (like in dxDrawText). Useful for centring and boxes fitted to text.
Syntax
float dxGetTextWidth(string text [, float scale = 1, string|font font = "default", bool colorCoded = false])Arguments
textstring- The text.
scalefloat, optional = 1- Scale.
fontstring|font, optional = "default"- Font.
colorCodedbool, optional = falsetrue= skip#RRGGBBcodes.
Returns
The width.
Example
local text = "Witaj na serwerze"
addEventHandler("onClientRender", root, function()
local w = dxGetTextWidth(text, 1.5, "default-bold")
dxDrawRectangle(20, 20, w + 20, 34, tocolor(0, 0, 0, 160))
dxDrawText(text, 30, 24, 0, 0, tocolor(255, 255, 255), 1.5, "default-bold")
end)