Skip to main content

Module text

Module text 

Source
Expand description

Text wrapping utilities shared by layout (measuring) and render (drawing).

Widths use Minecraft’s default (ASCII) font advance table so that wrapping and centering match what the MC text renderer actually draws.

Constants§

CHAR_W
Approximate pixel width per character at font_scale=1.0 (fallback for non-ASCII chars and legacy callers).
LINE_GAP
Gap between wrapped lines.
LINE_H
Line height at font_scale=1.0 (MC font is 9px; Patchouli uses 9-10px lines).

Functions§

char_width
Advance width in pixels (including 1px inter-glyph spacing) of one char in Minecraft’s default ASCII font at GUI scale 1.
line_count
Number of lines that text wraps to.
paginate_text
Split text into page-sized chunks that fit within max_h pixels. Each page is a Vec<String> of ready-to-render lines.
str_width
Pixel width of a string at the given font scale.
text_height
Total pixel height of wrapped text.
wrap_text
Break text into lines that fit within max_w pixels at font_scale. Width accounting is per-glyph (MC default font advances).