dxGetTextSize | Multi Theft Auto: Wiki Skip to content

dxGetTextSize

Client-side
Server-side
Shared

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


This function retrieves the theoretical width and height (in pixels) of a certain piece of text, if it were to be drawn using dxDrawText.

OOP Syntax Help! I don't understand this!

  • Note: This syntax requires you to ignore the font argument above

  • Method: font:getSize(...)

Syntax

float,​ float dxGetTextSize ( string text, [ float width = 0, float scaleXY = 1.0 [, float scaleY = 1.0 ], mixed font = "default", bool wordBreak = false, bool colorCoded = false ] )
Required Arguments
  • text: A string representing the text for which you wish to retrieve with width for.
Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.

  • width (default: 0): MISSING_PARAM_DESC
  • scaleXY (default: 1.0 [, float scaleY = 1.0 ]): MISSING_PARAM_DESC
  • font (default: "default"): MISSING_PARAM_DESC
  • wordBreak (default: false): MISSING_PARAM_DESC
  • colorCoded (default: false): MISSING_PARAM_DESC

Returns

  • float: value1
  • float: value2

Returns two floats representing the width and height of the text in pixels.

Code Examples

shared

This example draws a text with black background at the bottom right corner of the screen.

local screenWidth, screenHeight = guiGetScreenSize()
local message = "Incredibly huuuuuuuge message"
local messageOffset = 32
local messagePadding = 16
local messageWidth = 256
function renderMessage()
local textWidth, textHeight = dxGetTextSize(message, messageWidth, 2, "default", true)
local x = screenWidth - textWidth - messageOffset
local y = screenHeight - textHeight - messageOffset
dxDrawRectangle(x - messagePadding, y - messagePadding, textWidth + messagePadding * 2, textHeight + messagePadding * 2, 0x80000000) -- draw background
dxDrawText(message, x, y, x + textWidth, y + textHeight, 0xFFFFFFFF, 2, "default", "left", "top", false, true)
end
addEventHandler("onClientRender", root, renderMessage)