DxGetTextWidth: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (add bcolorcoded)
Line 5: Line 5:
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
float dxGetTextWidth ( string text, [float scale=1, mixed font="default"] )
float dxGetTextWidth ( string text, [float scale=1, mixed font="default", bool bColorCoded=false] )
</syntaxhighlight>
</syntaxhighlight>


Line 15: Line 15:
* '''scale:''' The size of the text.
* '''scale:''' The size of the text.
* '''font:''' Either a custom [[DX font]] element or the name of a built-in dx font:
* '''font:''' Either a custom [[DX font]] element or the name of a built-in dx font:
* '''bColorCoded:''' Should we exclude color codes from the width? (false will include the hex in the length)
{{DxFonts}}
{{DxFonts}}



Revision as of 04:50, 23 November 2014

This function retrieves the theoretical width of a certain piece of text, if it were to be drawn using dxDrawText.

Syntax

float dxGetTextWidth ( string text, [float scale=1, mixed 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. For more information on optional arguments, see optional arguments.

  • scale: The size of the text.
  • font: Either a custom DX font element or the name of a built-in dx font:
  • bColorCoded: Should we exclude color codes from the width? (false will include the hex in the length)
    • "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

Returns

Returns the float of the width of the text.

Example

Click to collapse [-]
Example

This will show you the width of a message in a normal chatbox sent by a player

function dxwidth(msg)
    chatbox = getChatboxLayout()
    local length = dxGetTextWidth(msg,chatbox["chat_scale"][1])
    outputChatBox(tostring(length))
end
addEventHandler("onClientChatMessage",getRootElement(),dxwidth)

See Also