You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
method to calculate the expected width of a given text and font size. How do you feel about this?
I'm currently exploring the avenue of preloading all chars of the text, then getting the character with opt_character(), and using advance_width() to calculate the final width.
pub fn calculate_text_width<'a>(text: &str, font_size: FontSize, glyphs: &'a GlyphCache) -> f32 {
let mut w = 0.0;
glyphs.preload_chars(font_size, text.chars());
for c in text.chars() {
if let Some(ch) = glyphs.opt_character(font_size, c) {
w += ch.advance_width() as f32;
}
}
w
}
But this feels cumbersome, and something so useful that should be provided by the library directly, no?
The text was updated successfully, but these errors were encountered:
I'm finding it hard to draw text centred around a point in the screen.
GlyphCache is probably too low-level to offer this functionality directly, but it could help with a
method to calculate the expected width of a given text and font size. How do you feel about this?
I'm currently exploring the avenue of preloading all chars of the text, then getting the character with opt_character(), and using advance_width() to calculate the final width.
But this feels cumbersome, and something so useful that should be provided by the library directly, no?
The text was updated successfully, but these errors were encountered: