Skip to main content

wrap_text

Function wrap_text 

Source
pub fn wrap_text(text: &str, max_width: f64, size: f64) -> Vec<String>
Expand description

Word-wraps text to lines no wider than max_width px at font size, measured with text_width (ggtext / str_wrap behaviour: break at whitespace; a single word wider than max_width on its own is hard-split so it never overflows the box). Returns vec![String::new()] for empty input and otherwise always at least one line, so a caller can take lines.len() as the wrapped block’s line count without a special case.

max_width <= 0.0 (or non-finite) disables wrapping — each word still splits only when it alone would overflow a positive width, so a degenerate width never panics or infinite-loops; it returns text unsplit as a single line (matching “no wrap requested”).