mod component;
pub mod prelude;
mod system;
pub use component::{
GlyphMesh, JustifyText, ScreenSize, ScreenSizeCamera, TextAnchor, TextMesh, TextMeshGlyphs,
TextMeshStyle,
};
pub use system::{
on_font_asset_event, scale_screen_size, update_glyph_meshes, FontMeshRegistry, GlyphMeshCache,
TextMeshComputed, TextMeshGlyphsComputed,
};
use bevy::prelude::*;
use std::marker::PhantomData;
use system::update_text_meshes;
struct SharedFontMeshPlugin;
impl Plugin for SharedFontMeshPlugin {
fn build(&self, app: &mut App) {
app.init_resource::<FontMeshRegistry>()
.init_resource::<GlyphMeshCache>()
.register_type::<TextMesh>()
.register_type::<TextMeshGlyphs>()
.register_type::<TextMeshStyle>()
.register_type::<TextAnchor>()
.register_type::<JustifyText>()
.register_type::<GlyphMesh>()
.register_type::<ScreenSize>()
.register_type::<ScreenSizeCamera>()
.add_systems(Update, update_text_meshes)
.add_systems(Update, on_font_asset_event)
.add_systems(PostUpdate, scale_screen_size);
}
}
pub struct FontMeshPlugin<M: Material = StandardMaterial>(PhantomData<M>);
impl<M: Material> Default for FontMeshPlugin<M> {
fn default() -> Self {
Self(PhantomData)
}
}
impl<M: Material> Plugin for FontMeshPlugin<M> {
fn build(&self, app: &mut App) {
if !app.is_plugin_added::<SharedFontMeshPlugin>() {
app.add_plugins(SharedFontMeshPlugin);
}
app.add_systems(Update, update_glyph_meshes::<M>);
}
}