pub fn fit_label(
text: &str,
width: f32,
advance: f32,
) -> Result<FittedLabel<'_>, UiError>Expand description
Fit monospaced text without shrinking its glyphs or allocating.
advance is the positive, finite glyph advance, not the font height. The
renderer’s bitmap font uses size * 0.75. Unicode scalar values count as one
glyph (unsupported glyphs are rendered as ?); UTF-8 is never split.
Newlines end the label and signal truncation. A width fitting fewer than three
glyphs shows only as many dots as fit; a zero width returns empty pieces.
Work is bounded by the visible prefix, even for very long input strings.
use ferravex_play::ui::fit_label;
let label = fit_label("COLLECT CRYSTALS", 90., 10.)?;
assert_eq!((label.prefix, label.suffix), ("COLLEC", "..."));
assert_eq!(label.width, 90.);