bevy/crates/bevy_text/src/font_loader.rs

26 lines
608 B
Rust
Raw Normal View History

2020-05-16 02:46:09 +00:00
use crate::Font;
use anyhow::Result;
use bevy_asset::{AssetLoader, LoadContext, LoadedAsset};
use bevy_utils::BoxedFuture;
2020-05-16 02:46:09 +00:00
2020-05-22 00:21:33 +00:00
#[derive(Default)]
2020-05-16 02:46:09 +00:00
pub struct FontLoader;
impl AssetLoader for FontLoader {
fn load<'a>(
&'a self,
bytes: &'a [u8],
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<()>> {
Box::pin(async move {
let font = Font::try_from_bytes(bytes.into())?;
load_context.set_default_asset(LoadedAsset::new(font));
Ok(())
})
2020-05-16 02:46:09 +00:00
}
2020-07-28 21:24:03 +00:00
2020-05-16 02:46:09 +00:00
fn extensions(&self) -> &[&str] {
2021-01-03 20:10:23 +00:00
&["ttf", "otf"]
2020-05-16 02:46:09 +00:00
}
}