Skip to content

Commit 943d83c

Browse files
authored
Use BSN helpers to initialize FontSource. (#23927)
Removes the complex `template` call and replaces it with the simpler BSN asset helper template.
1 parent f794d8a commit 943d83c

1 file changed

Lines changed: 17 additions & 32 deletions

File tree

  • crates/bevy_feathers/src/display

crates/bevy_feathers/src/display/label.rs

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
11
//! BSN scene function for displaying a plain text string in the correct font.
22
use bevy_app::PropagateOver;
3-
use bevy_asset::AssetServer;
4-
use bevy_ecs::template::template;
53
use bevy_scene::{bsn, Scene};
6-
use bevy_text::{FontSource, FontWeight, TextFont};
4+
use bevy_text::{FontSourceTemplate, FontWeight, TextFont};
75
use bevy_ui::widget::Text;
86

9-
use crate::{
10-
constants::{fonts, size},
11-
theme::ThemeTextColor,
12-
tokens,
13-
};
7+
use crate::{constants::size, theme::ThemeTextColor, tokens};
148

159
/// A text label.
1610
pub fn label(text: impl Into<String>) -> impl Scene {
1711
bsn! {
1812
Text(text)
19-
template(|ctx| {
20-
Ok(TextFont {
21-
font: FontSource::Handle(ctx.resource::<AssetServer>().load(fonts::REGULAR)),
22-
font_size: size::MEDIUM_FONT,
23-
weight: FontWeight::NORMAL,
24-
..Default::default()
25-
})
26-
})
13+
TextFont {
14+
font: FontSourceTemplate::Handle("fonts/FiraSans-Bold.ttf"),
15+
font_size: size::MEDIUM_FONT,
16+
weight: FontWeight::NORMAL,
17+
}
2718
PropagateOver<TextFont>
2819
ThemeTextColor(tokens::TEXT_MAIN)
2920
}
@@ -33,14 +24,11 @@ pub fn label(text: impl Into<String>) -> impl Scene {
3324
pub fn label_dim(text: impl Into<String>) -> impl Scene {
3425
bsn! {
3526
Text(text)
36-
template(|ctx| {
37-
Ok(TextFont {
38-
font: FontSource::Handle(ctx.resource::<AssetServer>().load(fonts::REGULAR)),
39-
font_size: size::MEDIUM_FONT,
40-
weight: FontWeight::NORMAL,
41-
..Default::default()
42-
})
43-
})
27+
TextFont {
28+
font: FontSourceTemplate::Handle("fonts/FiraSans-Bold.ttf"),
29+
font_size: size::MEDIUM_FONT,
30+
weight: FontWeight::NORMAL,
31+
}
4432
PropagateOver<TextFont>
4533
ThemeTextColor(tokens::TEXT_DIM)
4634
}
@@ -50,14 +38,11 @@ pub fn label_dim(text: impl Into<String>) -> impl Scene {
5038
pub fn label_small(text: impl Into<String>) -> impl Scene {
5139
bsn! {
5240
Text(text)
53-
template(|ctx| {
54-
Ok(TextFont {
55-
font: FontSource::Handle(ctx.resource::<AssetServer>().load(fonts::REGULAR)),
56-
font_size: size::EXTRA_SMALL_FONT,
57-
weight: FontWeight::NORMAL,
58-
..Default::default()
59-
})
60-
})
41+
TextFont {
42+
font: FontSourceTemplate::Handle("fonts/FiraSans-Bold.ttf"),
43+
font_size: size::EXTRA_SMALL_FONT,
44+
weight: FontWeight::NORMAL,
45+
}
6146
PropagateOver<TextFont>
6247
ThemeTextColor(tokens::TEXT_MAIN)
6348
}

0 commit comments

Comments
 (0)