Function measure_text_styled

Source
pub fn measure_text_styled(text: &str, style: TextStyle) -> TextMetrics
Expand description

Measures styled text exactly as draw_text_styled lays it out. Invalid styles (non-finite or nonpositive size) measure as empty.

use ferravex_render::{Color, text::{TextStyle, measure_text_styled}};
let style = TextStyle::modern(8., Color::new(1., 1., 1., 1.));
let m = measure_text_styled("Hi", style);
assert_eq!(m.width, 7.); // H (5) + spacing (1) + i (1)
assert_eq!((m.line_height, m.cap_height, m.ascent, m.descent), (14., 8., 11., 2.));
let two = measure_text_styled("Hi\nthere", style);
assert_eq!((two.line_count, two.height), (2, 27.));