Expand description
Text wrapping utilities shared by layout (measuring) and render (drawing).
Every font (Style::font: the game’s default, a Yog font, or a game
font by Yog’s alias such as "yog:font/uniform") is measured by the
host’s text renderer once use_host_metrics has been called
(UiRoot::render does it) — what the game draws, resource packs and
all. Before that, and outside a game, the default font’s advances
(data/glyph_widths.ydata, generated from the game’s font) stand in.
Constants§
- CHAR_W
- Approximate pixel width per character at font_scale=1.0 (fallback for non-ASCII chars and legacy callers).
- DEFAULT_
FONT - The font text is drawn in by default (the game’s).
- GLYPH_H
- The glyphs’ height, without the line’s room below them: what the game centres a line by.
- 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 font at GUI scale 1, as the game’s font has it;
beyond ASCII (glyphs vary)
CHAR_W. - char_
width_ in - Advance width of
cinfontat scale 1 — the host’s measurement (cached), else the default font’s table. - is_
default_ font - Whether
fontmeans the game’s default font (empty oryog:font/default). - line_
count - Number of lines that
textwraps to. - paginate_
text - Split
textinto page-sized chunks that fit withinmax_hpixels. Each page is aVec<String>of ready-to-render lines. - str_
width - Pixel width of a string at the given font scale.
- str_
width_ in str_widthinfont(seechar_width_in).- text_
height - Total pixel height of wrapped
text. - text_
height_ in text_heightinfont(seechar_width_in).- use_
host_ metrics - Lets every font 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
textinto lines that fit withinmax_wpixels atfont_scale. Width accounting is per-glyph (MC default font advances). - wrap_
text_ in wrap_textinfont(seechar_width_in).