simvx.graphics.draw2d_text¶
MSDF text rendering for Draw2D.
Handles font loading, glyph layout, and text measurement using the shared TextRenderer and MSDF atlas infrastructure.
Module Contents¶
Classes¶
Mixin providing MSDF text rendering and measurement for Draw2D. |
Data¶
API¶
- simvx.graphics.draw2d_text.log¶
‘getLogger(…)’
- class simvx.graphics.draw2d_text.Draw2DTextMixin[source]¶
Mixin providing MSDF text rendering and measurement for Draw2D.
- classmethod set_font(path: str | None = None, size: int = 48) None[source]¶
Load an MSDF font atlas via the shared TextRenderer.
- classmethod draw_text(text, pos=None, *, colour=None, scale=1.0, rect=None, alignment='left', vertical_alignment='top', fit_to_width=False, min_scale=None)[source]¶
Draw text at
posor insiderectwith optional alignment.Two positioning modes:
pos=(x, y): text top-left at the given coordinate (legacy form).rect=(x, y, w, h): text positioned byalignment(left/center/ right) andvertical_alignment(top/center/bottom) inside the rect.fit_to_width=Trueshrinksscaleso the text fitsrect.w, clamped tomin_scale.
min_scalesemantics:None(default): the readable-pixel safety net (~10px) is applied automatically. Tinyscalevalues are silently bumped up so MSDF glyphs stay legible.explicit value: the caller’s floor is honoured exactly. The readable safety net is bypassed: the caller has taken responsibility for legibility (e.g. shrinking labels to fit a cramped inventory cell).
- classmethod text_height(text, scale=1.0)[source]¶
Height of
textin pixels atscale.Multi-line strings (containing
\n) accumulate line heights using the font’s line-height metric. Returns 0 for empty input.
- classmethod fit_scale(text, max_width, *, base_scale=1.0, min_scale=None)[source]¶
Largest scale ≤
base_scalethat fitstextwithinmax_width.Returns
base_scalewhen the text already fits or when inputs are degenerate. The returned value matches what :meth:draw_textwould actually use, so callers can compute width metrics that align with what’s drawn.min_scalesemantics mirror :meth:draw_text:None(default): clamps from below by the readable-pixel floor (~10px) so the returned scale never produces illegible MSDF output.explicit value: the caller’s floor is honoured exactly, bypassing the readable safety net.