Function wrap_lines

Source
pub fn wrap_lines(
    text: &str,
    max_w_px: f32,
    font: FontId,
    px_size: u16,
    m: &dyn TextMeasure,
) -> Vec<String>
Expand description

Word-wraps text without hyphenation.

max_w_px is a non-negative logical-pixel target; negative and NaN values behave as zero. Runs of Unicode whitespace, including explicit newlines, are normalized to one ASCII space within an output line. A word wider than the target is emitted intact, so this is not a hard width bound. The result always contains at least one line, with an empty string for whitespace-only input.

ยงExamples

use ailloli_ui_core::FontId;
use ailloli_ui_text::{wrap_lines, ApproxTextMeasure};

let lines = wrap_lines("one   two three", 41.0, FontId::Ui, 10, &ApproxTextMeasure);
assert_eq!(lines, ["one two", "three"]);
assert_eq!(wrap_lines(" \n ", 20.0, FontId::Ui, 10, &ApproxTextMeasure), [""]);