Module text_layout

Source
Expand description

Borrowed word wrapping for the UI’s existing 5×7 bitmap font.

Coordinates are logical UI units, before viewport scaling. Each Unicode scalar occupies one cell; UI painting uppercases ASCII and substitutes ? for unsupported glyphs. This is not shaping or a second font engine.

Wrapping deliberately matches super::Ui::text: LF separates lines, internal blank lines survive, and a final LF does not add another line. Spaces, tabs and CR at a word-wrap boundary are skipped; otherwise whitespace occupies cells (including CR before LF). Unicode whitespace can be a word boundary, but only those three ASCII characters are skipped after it. This differs from immediate-font measure_multiline’s CRLF/trailing-line convention; that API is unchanged.

A content-sized briefing/card at a 320-unit viewport width:

use ferravex_render::ui::{TextStyle, Ui, UiRect, Viewport};
use ferravex_render::ui::text_layout::{LineLimit, WrappedText};
let copy = "Collect the amber keys before opening the gate.\n\n\
            Return to the checkpoint if the route is blocked.";
let style = TextStyle { size: 18., wrap: true, ..Default::default() };
let limit = LineLimit::Unlimited; // Or Ellipsis(4) for a compact card.
let layout = WrappedText::new(copy, 288., style.size)?.with_limit(limit);
let measured = layout.measure();
let mut ui = Ui::new(); // Reuse across frames.
ui.begin(Viewport::responsive([320., 400.], [0.; 4])?);
let body = UiRect { min: [16., 24.], size: [288., measured.height] };
assert_eq!(ui.wrapped_text(body, copy, style, limit)?, measured);
ui.paint();
// Place the next block at body.min[1] + measured.height + your chosen gap.

Structs§

TextBlockMetrics
Line-slot measurements, before rectangle/scissor clipping and without shadows. Unlike tight ink bounds, height reserves a full line advance for the last line.
TextLine
One borrowed line. text followed by suffix is the complete displayed copy. Empty lines still occupy one line slot. Ranges are always UTF-8 boundaries.
WrappedLines
Restartable via WrappedText::lines, cloneable, constant-storage line cursor.
WrappedText
Immutable borrowed layout. Construction and iteration allocate no storage; each measurement scans the source to count hidden lines as well as visible ones. Work is linear in source length, not bounded by the line limit. Self::lines starts a fresh iterator, so reflow needs no retained cache/reset.

Enums§

LineLimit
An explicit count of retained lines, independent of rectangle/scissor clipping. Zero retains no lines. Neither policy changes font size or line breaking.