GetTextWidth

Measure the pixel width of a text string at a given font size.

Syntax

Susano.GetTextWidth(text, size_px) -> number

Parameters

text (string): UTF-8 text to measure.

size_px (number): Font size in pixels. If 0, uses default font size.

Return(s)

number: Width in pixels. 0 if no result was available within the internal timeout.

Behavior

Enqueues a measurement request and waits briefly for the Overlay thread to compute width.

Non-drawing operation; does not affect the build buffer.

Result depends on the active Overlay font.

Example(s)

local w = Susano.GetTextWidth("hello overlay", 18)
Susano.BeginFrame()
Susano.DrawRect(100, 240, w + 10, 24, 1,1,1, 1, 1)
Susano.DrawText(105, 260, "hello overlay", 18, 1,1,1, 1)
Susano.SubmitFrame()

Last updated