Do not assume font handle is present in assets. (#490)
This commit is contained in:
parent
4b83cfc729
commit
b9f18efd86
@ -52,7 +52,8 @@ impl FontAtlasSet {
|
||||
font_size: f32,
|
||||
text: &str,
|
||||
) -> f32 {
|
||||
let font = fonts.get(&self.font).unwrap();
|
||||
let mut width = 0.0;
|
||||
if let Some(font) = fonts.get(&self.font) {
|
||||
let scaled_font = ab_glyph::Font::as_scaled(&font.font, font_size);
|
||||
let font_atlases = self
|
||||
.font_atlases
|
||||
@ -66,7 +67,6 @@ impl FontAtlasSet {
|
||||
});
|
||||
|
||||
let mut last_glyph: Option<Glyph> = None;
|
||||
let mut width = 0.0;
|
||||
for character in text.chars() {
|
||||
if character.is_control() {
|
||||
continue;
|
||||
@ -100,10 +100,11 @@ impl FontAtlasSet {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
width += scaled_font.h_advance(glyph.id);
|
||||
last_glyph = Some(glyph);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
width
|
||||
}
|
||||
|
||||
@ -61,9 +61,10 @@ pub fn draw_text_system(
|
||||
mut query: Query<(&mut Draw, &Text, &Node, &GlobalTransform)>,
|
||||
) {
|
||||
for (mut draw, text, node, global_transform) in &mut query.iter() {
|
||||
if let Some(font) = fonts.get(&text.font) {
|
||||
let position = global_transform.translation() - (node.size / 2.0).extend(0.0);
|
||||
let mut drawable_text = DrawableText {
|
||||
font: fonts.get(&text.font).unwrap(),
|
||||
font,
|
||||
font_atlas_set: font_atlas_sets
|
||||
.get(&text.font.as_handle::<FontAtlasSet>())
|
||||
.unwrap(),
|
||||
@ -79,3 +80,4 @@ pub fn draw_text_system(
|
||||
drawable_text.draw(&mut draw, &mut draw_context).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user