dxGetTextWidth
Client-side
Server-side
Shared
This function retrieves the theoretical width (in pixels) of a certain piece of text, if it were to be drawn using dxDrawText.
Note
This function already takes the client's screen resolution into account.
OOP Syntax Help! I don't understand this!
-
Note: This syntax requires you to ignore the font argument below.
- Method:dx-font:getTextWidth(...)
Syntax
float|false dxGetTextWidth ( string text, [ float scale = 1, string/dx-font font = "default", bool bColorCoded = 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.
- scale (default: 1): The size of the text.
- font (default: "default"): Either a custom DX font element or the name of a built-in dx font.
- default: Tahoma
- default-bold: Tahoma Bold
- clear: Verdana
- arial: Arial
- sans: Microsoft Sans Serif
- pricedown: Pricedown (GTA's theme text)
- bankgothic: Bank Gothic Medium
- diploma: Diploma Regular
- beckett: Beckett Regular
- unifont: Unifont
- bColorCoded (default: false): Should we exclude color codes from the width? (false will include the hex in the length).
Returns
- float|false: width
Returns the float of the width of the text (in pixels) or false if invalid arguments passed.
Code Examples
client
This will show you the width of a message in a normal chatbox sent by a player.
function dxwidth(msg) local chatbox = getChatboxLayout() local length = dxGetTextWidth(msg,chatbox["chat_scale"][1]) outputChatBox(tostring(length))endaddEventHandler("onClientChatMessage",root,dxwidth)See Also
Drawing Functions
- dxConvertPixels
- dxCreateFont
- dxCreateRenderTargetUpdated
- dxCreateScreenSource
- dxCreateShader
- dxCreateTextureUpdated
- dxDrawCircle
- dxDrawImage
- dxDrawImageSection
- dxDrawLine
- dxDrawLine3D
- dxDrawMaterialLine3D
- dxDrawMaterialPrimitive
- dxDrawMaterialPrimitive3D
- dxDrawMaterialSectionLine3D
- dxDrawModel3DNew
- dxDrawPrimitive
- dxDrawPrimitive3D
- dxDrawRectangle
- dxDrawText
- dxDrawWiredSphere
- dxGetBlendMode
- dxGetFontHeight
- dxGetMaterialSize
- dxGetPixelColor
- dxGetPixelsFormat
- dxGetPixelsSize
- dxGetStatusUpdated
- dxGetTextSize
- dxGetTexturePixelsUpdated
- dxGetTextWidth
- dxIsAspectRatioAdjustmentEnabled
- dxSetAspectRatioAdjustmentEnabled
- dxSetBlendMode
- dxSetPixelColor
- dxSetRenderTarget
- dxSetShaderTessellation
- dxSetShaderTransform
- dxSetShaderValue
- dxSetTestMode
- dxSetTextureEdge
- dxSetTexturePixels
- dxUpdateScreenSource