Skip to main content

wrap

Function wrap 

Source
pub fn wrap(line: &Line, max_width: u16) -> Vec<Line>
Expand description

Word-wraps line to max_width columns, returning the broken-apart Lines.

This is the same greedy, grapheme-cluster-aware wrap pass TextLayout runs internally on every render (breaking on ASCII space, honoring hard \ns, force-breaking an overlong word at the column boundary); it’s exposed standalone for callers that need the wrapped pieces themselves rather than having them written straight to a surface, such as a scrollback log that wraps each message into rows while still addressing its window in whole messages.

Each returned Line is a single unstyled or uniformly-styled run per source span that survived onto that row; adjacent graphemes carrying the same Style are coalesced back into one Span, so wrapping a plain Line::raw round-trips to plain Line::raw rows.

§Examples

use retroglyph_core::layout::wrap;
use retroglyph_core::text::Line;

let line = Line::raw("hello world");
let rows = wrap(&line, 7);
assert_eq!(rows.len(), 2);
assert_eq!(rows[0].spans[0].content, "hello");
assert_eq!(rows[1].spans[0].content, "world");