simvx.core.ui.text_paragraph¶
TextParagraph: pure-function word-wrap helper for variable-width text.
Editor tooltips, tour-guide popups, and game dialog boxes all need the same
recipe: given a max width and a font size, break a paragraph into lines that
fit, then return the wrapped lines plus the total block height. Callers
previously hand-rolled this against renderer.text_width().
wrap_paragraph is a free function so it stays usable from any draw path
(widget, Node2D, or raw on_draw callback) without coupling to a
specific widget class.
Example::
from simvx.core.ui import wrap_paragraph
lines, h = wrap_paragraph(text, max_width=200, renderer=renderer, font_size=14)
for i, line in enumerate(lines):
renderer.draw_text(line, (x, y + i * (14 * 1.2)), scale=1.0)
Module Contents¶
Classes¶
Result of :func: |
Functions¶
Word-wrap |
Data¶
API¶
- simvx.core.ui.text_paragraph.__all__¶
[‘TextParagraph’, ‘wrap_paragraph’]
- class simvx.core.ui.text_paragraph.TextParagraph[source]¶
Result of :func:
wrap_paragraph: wrapped lines + measured dimensions.- lines: tuple[str, ...]¶
None
- total_height: float¶
None
- max_line_width: float¶
None
- line_height: float¶
None
- simvx.core.ui.text_paragraph.wrap_paragraph(text: str, *, max_width: float, renderer, font_size: float = 14.0, line_height_factor: float = _LINE_HEIGHT_FACTOR) simvx.core.ui.text_paragraph.TextParagraph[source]¶
Word-wrap
textto fit withinmax_widthpixels.The renderer is queried via
renderer.text_width(line, scale): any renderer that implements the Draw2D contract (the real one,- Class:
simvx.core.ui.DrawLogin tests, …) works.
Hard newlines (
\n) are honoured as paragraph breaks. Words longer thanmax_widthare emitted on their own line and overflow horizontally rather than being split mid-glyph (left-to-right text only: defer complex shaping to a freetype rewrite).Args: text: Source text. May contain
\n. max_width: Wrap width in pixels. renderer: Object exposingtext_width(str, scale) -> float. font_size: Font size in pixels. Determinesscale = font_size / 14for the underlying measurement. line_height_factor: Multiplier applied tofont_sizefor the inter-line pitch (default 1.2).Returns: :class:
TextParagraphwith the wrapped lines and the total block height for vertical layout.