D3d.MeasureText
From Nomad DB
Revision as of 22:19, 2 August 2020 by Jan (talk | contribs) (Created page with "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.
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