From 85397575696dea84619946201b73391a04840502 Mon Sep 17 00:00:00 2001 From: Linwei Zhang Date: Mon, 24 Jul 2023 10:54:56 +0800 Subject: [PATCH 1/2] Update text example using default font --- examples/ui/text.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/ui/text.rs b/examples/ui/text.rs index ccc44f5095039..af24c35691e0e 100644 --- a/examples/ui/text.rs +++ b/examples/ui/text.rs @@ -24,7 +24,7 @@ struct FpsText; #[derive(Component)] struct ColorText; -fn setup(mut commands: Commands, asset_server: Res) { +fn setup(mut commands: Commands) { // UI camera commands.spawn(Camera2dBundle::default()); // Text with one section @@ -34,9 +34,10 @@ fn setup(mut commands: Commands, asset_server: Res) { // Accepts a `String` or any type that converts into a `String`, such as `&str` "hello\nbevy!", TextStyle { - font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 100.0, color: Color::WHITE, + // If no font is specified, it will use the default font. + ..default() }, ) // Set the alignment of the Text .with_text_alignment(TextAlignment::Center) @@ -56,15 +57,17 @@ fn setup(mut commands: Commands, asset_server: Res) { TextSection::new( "FPS: ", TextStyle { - font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 60.0, color: Color::WHITE, + // If no font is specified, it will use the default font. + ..default() }, ), TextSection::from_style(TextStyle { - font: asset_server.load("fonts/FiraMono-Medium.ttf"), font_size: 60.0, color: Color::GOLD, + // If no font is specified, it will use the default font. + ..default() }), ]), FpsText, From b75a48f9b2976023fea843f31d3ecf668035fa9d Mon Sep 17 00:00:00 2001 From: Linwei Zhang Date: Mon, 24 Jul 2023 18:48:00 +0800 Subject: [PATCH 2/2] Apply review suggestion --- examples/ui/text.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/ui/text.rs b/examples/ui/text.rs index af24c35691e0e..6db570f19c048 100644 --- a/examples/ui/text.rs +++ b/examples/ui/text.rs @@ -24,7 +24,7 @@ struct FpsText; #[derive(Component)] struct ColorText; -fn setup(mut commands: Commands) { +fn setup(mut commands: Commands, asset_server: Res) { // UI camera commands.spawn(Camera2dBundle::default()); // Text with one section @@ -34,10 +34,10 @@ fn setup(mut commands: Commands) { // Accepts a `String` or any type that converts into a `String`, such as `&str` "hello\nbevy!", TextStyle { + // This font is loaded and will be used instead of the default font. + font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 100.0, color: Color::WHITE, - // If no font is specified, it will use the default font. - ..default() }, ) // Set the alignment of the Text .with_text_alignment(TextAlignment::Center) @@ -57,10 +57,10 @@ fn setup(mut commands: Commands) { TextSection::new( "FPS: ", TextStyle { + // This font is loaded and will be used instead of the default font. + font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 60.0, color: Color::WHITE, - // If no font is specified, it will use the default font. - ..default() }, ), TextSection::from_style(TextStyle {