Function wrap_text

Source
pub fn wrap_text(text: &str, max_width: f32, style: TextStyle) -> WrapLines<'_> ⓘ
Expand description

Greedy word-wrapped lines of text no wider than max_width (logical units). Explicit \n breaks are kept; runs of spaces at a wrap are dropped; a word wider than the limit is split between characters. Borrowed slices, no allocation.

use ferravex_render::{Color, text::{TextStyle, text_width, wrap_text}};
let s = TextStyle::modern(8., Color::new(1., 1., 1., 1.));
let lines: Vec<&str> = wrap_text("Press Space to jump over the gap", 60., s).collect();
assert_eq!(lines, ["Press Space", "to jump over", "the gap"]);
assert!(lines.iter().all(|l| text_width(l, s) <= 60.));