DRAWING FUNCTIONS
GetTextWidth
Measures the width of a string for the given font.
Syntax
local width = ONYX.GetTextWidth(text, size_px)Parameters
text(string) — UTF-8 text to measure.size_px(number) — Font size in pixels; 0 uses the default font size.
Return(s)
width (number) — pixel width, or 0 when no result arrived before the timeout.
Behavior
- Queues a measurement request and waits briefly for the overlay thread to compute the width.
- It is a non-drawing call and does not affect the build buffer.
- The result depends on the active overlay font.
Example(s)
local w = ONYX.GetTextWidth("hello overlay", 16)
ONYX.BeginFrame()
ONYX.DrawRectFilled(100, 240, w + 24, 24, 0, 0, 0, 0.4)
ONYX.DrawText(112, 244, "hello overlay", 16, 1, 1, 1, 1)
ONYX.SubmitFrame()