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. Other fonts (Style::font, e.g. "minecraft:uniform" or a resource-pack font) are measured by the host’s text renderer once use_host_metrics has been called (UiRoot::render does it); before that, and outside a game, they fall back to the default font’s table.

Constants§

CHAR_W
Approximate pixel width per character at font_scale=1.0 (fallback for non-ASCII chars and legacy callers).
DEFAULT_FONT
Minecraft’s default font id — what an empty Style::font means.
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.
char_width_in
Advance width of c in font at scale 1 — the default font’s table, or the host’s measurement (cached) for any other font.
is_default_font
Whether font means Minecraft’s default font (empty or minecraft:default).
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.
str_width_in
str_width in font (see char_width_in).
text_height
Total pixel height of wrapped text.
text_height_in
text_height in font (see char_width_in).
use_host_metrics
Lets non-default fonts be measured by the host’s text renderer (see the module docs). Called by UiRoot::render; call it yourself before the first layout to get exact metrics from the very first frame.
wrap_text
Break text into lines that fit within max_w pixels at font_scale. Width accounting is per-glyph (MC default font advances).
wrap_text_in
wrap_text in font (see char_width_in).