bevy/crates/bevy_text/src/font_loader.rs
2021-01-03 12:10:23 -08:00

25 lines
608 B
Rust

use crate::Font;
use anyhow::Result;
use bevy_asset::{AssetLoader, LoadContext, LoadedAsset};
use bevy_utils::BoxedFuture;
#[derive(Default)]
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(())
})
}
fn extensions(&self) -> &[&str] {
&["ttf", "otf"]
}
}