1#![allow(internal_features)]
2#![cfg_attr(any(docsrs, docsrs_dep), feature(rustdoc_internals))]
3#![doc = include_str!("../README.md")]
4#![cfg_attr(doc, deny(missing_docs))]
5
6pub use cosmic_text;
7
8pub mod atlas;
9pub mod def;
10pub mod layout;
11
12use bevy_ecs::prelude::*;
13
14pub mod prelude {
16 pub use crate::{
17 atlas::ExtractedFontAtlases,
18 def::{Font, Text, TextAlign, TextFont, TextGlyph, TextGlyphs, TextSpan, TextStructure, TextWrap},
19 layout::FontLayout,
20 };
21}
22
23pub mod plugin {
25 use std::sync::Mutex;
26
27 use bevy_app::{PluginGroupBuilder, prelude::*};
28 use bevy_asset::AssetApp;
29 use bevy_ecs::prelude::IntoSystemConfigs;
30 use bevy_render::{ExtractSchedule, RenderApp};
31
32 use crate::{
33 HephaeTextSystems,
34 atlas::{ExtractedFontAtlases, FontAtlas, extract_font_atlases},
35 def::{Font, FontLoader, Text, TextAlign, TextFont, TextSpan, TextWrap, compute_structure, notify_structure},
36 layout::{FontLayout, FontLayoutInner, load_fonts_to_database},
37 };
38
39 pub fn text() -> impl PluginGroup {
41 struct TextGroup;
42 impl PluginGroup for TextGroup {
43 fn build(self) -> PluginGroupBuilder {
44 #[allow(unused_mut)]
45 let mut builder = PluginGroupBuilder::start::<Self>().add(|app: &mut App| {
46 let (sender, receiver) = async_channel::bounded(4);
47 app.init_asset::<Font>()
48 .init_asset::<FontAtlas>()
49 .register_asset_loader(FontLoader { add_to_database: sender })
50 .insert_resource(FontLayout(Mutex::new(FontLayoutInner::new(receiver))))
51 .register_type::<Text>()
52 .register_type::<TextWrap>()
53 .register_type::<TextAlign>()
54 .register_type::<TextFont>()
55 .register_type::<TextSpan>()
56 .configure_sets(Update, HephaeTextSystems::LoadFontsToDatabase)
57 .configure_sets(PostUpdate, HephaeTextSystems::ComputeStructure)
58 .add_systems(Update, load_fonts_to_database.in_set(HephaeTextSystems::LoadFontsToDatabase))
59 .add_systems(
60 PostUpdate,
61 (compute_structure, notify_structure)
62 .chain()
63 .in_set(HephaeTextSystems::ComputeStructure),
64 );
65
66 if let Some(render_app) = app.get_sub_app_mut(RenderApp) {
67 render_app
68 .init_resource::<ExtractedFontAtlases>()
69 .configure_sets(ExtractSchedule, HephaeTextSystems::ExtractFontAtlases)
70 .add_systems(
71 ExtractSchedule,
72 extract_font_atlases.in_set(HephaeTextSystems::ExtractFontAtlases),
73 );
74 }
75 });
76
77 #[cfg(feature = "locale")]
78 {
79 builder = builder
80 .add(hephae_locale::plugin::locale_target::<Text>())
81 .add(hephae_locale::plugin::locale_target::<TextSpan>());
82 }
83
84 builder
85 }
86 }
87
88 TextGroup
89 }
90}
91
92#[derive(SystemSet, Debug, Copy, Clone, PartialEq, Eq, Hash)]
94pub enum HephaeTextSystems {
95 ExtractFontAtlases,
98 LoadFontsToDatabase,
101 ComputeStructure,
105}