ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Client functions
  3. dxGetTextWidth

Function

dxGetTextWidth

ClientDrawing (dx)Identical to MTA:SA

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 = false
true = skip #RRGGBB codes.

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)

See also