1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

Return 0.0 if font not found in glyph_width instead of panic (#7559)

This commit is contained in:
Lucas Meurer
2025-09-30 10:12:56 +02:00
committed by GitHub
parent 5ee88da61c
commit 47c5617740
2 changed files with 16 additions and 6 deletions

View File

@@ -478,12 +478,11 @@ impl Font<'_> {
/// Width of this character in points.
pub fn glyph_width(&mut self, c: char, font_size: f32) -> f32 {
let (key, glyph_info) = self.glyph_info(c);
let font = &self
.fonts_by_id
.get(&key)
.expect("Nonexistent font ID")
.ab_glyph_font;
glyph_info.advance_width_unscaled.0 * font.px_scale_factor(font_size)
if let Some(font) = &self.fonts_by_id.get(&key) {
glyph_info.advance_width_unscaled.0 * font.ab_glyph_font.px_scale_factor(font_size)
} else {
0.0
}
}
/// Can we display this glyph?