diff --git a/crates/bevy_text/src/text.rs b/crates/bevy_text/src/text.rs index ac1aa9bdae42d..cad9b171d7411 100644 --- a/crates/bevy_text/src/text.rs +++ b/crates/bevy_text/src/text.rs @@ -264,7 +264,7 @@ impl From for parley::Alignment { } } -#[derive(Clone, Debug, Reflect, PartialEq)] +#[derive(Clone, Debug, Reflect, PartialEq, FromTemplate)] /// Determines how the font face for a text sections is selected. /// /// A [`FontSource`] can be a handle to a font asset, a font family name, @@ -287,6 +287,7 @@ pub enum FontSource { /// `FiraMono-subset.ttf` compiled into the library is used. /// * otherwise no text will be rendered, unless a custom font is loaded into the default font /// handle. + #[default] Handle(Handle), /// Resolve the font by family name using the font database. Family(SmolStr), @@ -370,7 +371,7 @@ impl From<&str> for FontSource { /// `TextFont` determines the style of a text span within a [`ComputedTextBlock`], specifically /// the font face, the font size, the line height, and the antialiasing method. -#[derive(Component, Clone, Debug, Reflect, PartialEq)] +#[derive(Component, Clone, Debug, Reflect, PartialEq, FromTemplate)] #[reflect(Component, Default, Debug, Clone)] pub struct TextFont { /// Specifies the font face used for this text section. diff --git a/examples/scene/bsn.rs b/examples/scene/bsn.rs index 6c8277d79ddd1..c8356204be41a 100644 --- a/examples/scene/bsn.rs +++ b/examples/scene/bsn.rs @@ -1,5 +1,5 @@ //! This example demonstrates how to use BSN to compose scenes. -use bevy::{ecs::template::template, prelude::*}; +use bevy::{prelude::*, text::FontSourceTemplate}; fn main() { App::new() @@ -51,16 +51,10 @@ fn button(label: &'static str) -> impl Scene { BackgroundColor(Color::srgb(0.15, 0.15, 0.15)) Children [( Text(label) - // The `template` wrapper can be used for types that can't implement or don't yet have a template - template(|context| { - Ok(TextFont { - font: context - .resource::() - .load("fonts/FiraSans-Bold.ttf").into(), - font_size: FontSize::Px(33.0), - ..default() - }) - }) + TextFont { + font: FontSourceTemplate::Handle("fonts/FiraSans-Bold.ttf"), + font_size: FontSize::Px(33.0), + } TextColor(Color::srgb(0.9, 0.9, 0.9)) TextShadow )]