Difference between revisions of "D3d.MeasureText"
From Nomad DB
Line 1: | Line 1: | ||
+ | {{Page_WD2}}{{Page_MDE}}{{Page_WDL}} | ||
Returns the measurements (width, height) of a text string. Font is set using [[d3d.SetFont]]. The measurements can be used to align text (like centering) within rectangles. | Returns the measurements (width, height) of a text string. Font is set using [[d3d.SetFont]]. The measurements can be used to align text (like centering) within rectangles. | ||
Line 26: | Line 27: | ||
==Related Pages== | ==Related Pages== | ||
− | *[[ | + | *[[ScriptHook: Rendering]] |
*[[d3d.SetFont]] | *[[d3d.SetFont]] | ||
*[[d3d.DrawText]] | *[[d3d.DrawText]] | ||
Line 33: | Line 34: | ||
[[Category:WD2 ScriptHook Lua]] | [[Category:WD2 ScriptHook Lua]] | ||
+ | [[Category:WDL ScriptHook Lua]] |
Latest revision as of 11:13, 15 April 2021
Returns the measurements (width, height) of a text string. Font is set using d3d.SetFont. The measurements can be used to align text (like centering) within rectangles.
This function can only be called from inside OnRender event!
Syntax
d3d.MeasureText(text)
- text: string (Text)
- Returns: width (number), height (number) of the given text
Example
Draws a red text on a white surface.
function script:OnRender()
d3d.SetFont("Arial", 20)
local w, h = d3d.MeasureText("Hello NomadDB!")
d3d.SetColor(255, 255, 255) --white
d3d.DrawRect(50, 50, w, h)
d3d.SetColor(255, 0, 0) --red
d3d.DrawText(50, 50, "Hello NomadDB!")
end