Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/bevy_text/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl From<Justify> 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,
Expand All @@ -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<Font>),
/// Resolve the font by family name using the font database.
Family(SmolStr),
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 5 additions & 11 deletions examples/scene/bsn.rs
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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::<AssetServer>()
.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
)]
Expand Down