diff --git a/Cargo.toml b/Cargo.toml index ba49a55ecd..d1cc871372 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,6 +52,7 @@ default = [ "bevy_gizmos", "android_shared_stdcxx", "tonemapping_luts", + "default_font", ] # Force dynamic linking, which improves iterative compile times @@ -225,6 +226,9 @@ accesskit_unix = ["bevy_internal/accesskit_unix"] # Enable assertions to check the validity of parameters passed to glam glam_assert = ["bevy_internal/glam_assert"] +# Include a default font, containing only ASCII characters, at the cost of a 20kB binary size increase +default_font = ["bevy_internal/default_font"] + [dependencies] bevy_dylib = { path = "crates/bevy_dylib", version = "0.11.0-dev", default-features = false, optional = true } bevy_internal = { path = "crates/bevy_internal", version = "0.11.0-dev", default-features = false } diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index 1f498e22c5..51fe644c92 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -97,6 +97,8 @@ bevy_render = ["dep:bevy_render", "bevy_scene?/bevy_render"] # Enable assertions to check the validity of parameters passed to glam glam_assert = ["bevy_math/glam_assert"] +default_font = ["bevy_text?/default_font"] + [dependencies] # bevy bevy_a11y = { path = "../bevy_a11y", version = "0.11.0-dev" } diff --git a/crates/bevy_text/Cargo.toml b/crates/bevy_text/Cargo.toml index e34ffad8f4..7e17ab8c56 100644 --- a/crates/bevy_text/Cargo.toml +++ b/crates/bevy_text/Cargo.toml @@ -10,6 +10,7 @@ keywords = ["bevy"] [features] subpixel_glyph_atlas = [] +default_font = [] [dependencies] # bevy diff --git a/crates/bevy_text/src/FiraMono-subset.ttf b/crates/bevy_text/src/FiraMono-subset.ttf new file mode 100644 index 0000000000..6989c2e483 Binary files /dev/null and b/crates/bevy_text/src/FiraMono-subset.ttf differ diff --git a/crates/bevy_text/src/lib.rs b/crates/bevy_text/src/lib.rs index a3478780de..4f9ab2497d 100644 --- a/crates/bevy_text/src/lib.rs +++ b/crates/bevy_text/src/lib.rs @@ -26,8 +26,11 @@ pub mod prelude { } use bevy_app::prelude::*; -use bevy_asset::AddAsset; +#[cfg(feature = "default_font")] +use bevy_asset::load_internal_binary_asset; +use bevy_asset::{AddAsset, HandleUntyped}; use bevy_ecs::prelude::*; +use bevy_reflect::TypeUuid; use bevy_render::{camera::CameraUpdateSystem, ExtractSchedule, RenderApp}; use bevy_sprite::SpriteSystem; use std::num::NonZeroUsize; @@ -67,6 +70,9 @@ pub enum YAxisOrientation { BottomToTop, } +pub const DEFAULT_FONT_HANDLE: HandleUntyped = + HandleUntyped::weak_from_u64(Font::TYPE_UUID, 1491772431825224042); + impl Plugin for TextPlugin { fn build(&self, app: &mut App) { app.add_asset::() @@ -98,5 +104,13 @@ impl Plugin for TextPlugin { extract_text2d_sprite.after(SpriteSystem::ExtractSprites), ); } + + #[cfg(feature = "default_font")] + load_internal_binary_asset!( + app, + DEFAULT_FONT_HANDLE, + "FiraMono-subset.ttf", + |bytes: &[u8]| { Font::try_from_bytes(bytes.to_vec()).unwrap() } + ); } } diff --git a/crates/bevy_text/src/text.rs b/crates/bevy_text/src/text.rs index 9d4a4c1615..c1e3584e39 100644 --- a/crates/bevy_text/src/text.rs +++ b/crates/bevy_text/src/text.rs @@ -6,6 +6,8 @@ use bevy_utils::default; use serde::{Deserialize, Serialize}; use crate::Font; +#[cfg(feature = "default_font")] +use crate::DEFAULT_FONT_HANDLE; #[derive(Component, Debug, Clone, Reflect)] #[reflect(Component, Default)] @@ -167,7 +169,7 @@ pub struct TextStyle { impl Default for TextStyle { fn default() -> Self { Self { - font: Default::default(), + font: DEFAULT_FONT_HANDLE.typed(), font_size: 12.0, color: Color::WHITE, } diff --git a/docs/cargo_features.md b/docs/cargo_features.md index f3ee40a873..d2a876d10f 100644 --- a/docs/cargo_features.md +++ b/docs/cargo_features.md @@ -27,6 +27,7 @@ The default feature set enables most of the expected features of a game engine, |bevy_text|Provides text functionality| |bevy_ui|A custom ECS-driven UI framework| |bevy_winit|winit window and input backend| +|default_font|Include a default font, containing only ASCII characters, at the cost of a 20kB binary size increase| |filesystem_watcher|Enable watching file system for asset hot reload| |hdr|HDR image format support| |ktx2|KTX2 compressed texture support| diff --git a/examples/2d/bloom_2d.rs b/examples/2d/bloom_2d.rs index 95b3323d5f..108cc94c57 100644 --- a/examples/2d/bloom_2d.rs +++ b/examples/2d/bloom_2d.rs @@ -72,9 +72,9 @@ fn setup( TextBundle::from_section( "", TextStyle { - font: asset_server.load("fonts/FiraMono-Medium.ttf"), font_size: 18.0, color: Color::WHITE, + ..default() }, ) .with_style(Style { diff --git a/examples/3d/3d_gizmos.rs b/examples/3d/3d_gizmos.rs index 6157ea8466..0499e6c66e 100644 --- a/examples/3d/3d_gizmos.rs +++ b/examples/3d/3d_gizmos.rs @@ -15,7 +15,6 @@ fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, - asset_server: Res, ) { commands.spawn(Camera3dBundle { transform: Transform::from_xyz(0., 1.5, 6.).looking_at(Vec3::ZERO, Vec3::Y), @@ -48,9 +47,9 @@ fn setup( commands.spawn(TextBundle::from_section( "Press 't' to toggle drawing gizmos on top of everything else in the scene", TextStyle { - font: asset_server.load("fonts/FiraMono-Medium.ttf"), font_size: 24., color: Color::WHITE, + ..default() }, )); } diff --git a/examples/3d/anti_aliasing.rs b/examples/3d/anti_aliasing.rs index 084a39a2eb..55ee85f863 100644 --- a/examples/3d/anti_aliasing.rs +++ b/examples/3d/anti_aliasing.rs @@ -329,9 +329,9 @@ fn setup( TextBundle::from_section( "", TextStyle { - font: asset_server.load("fonts/FiraMono-Medium.ttf"), font_size: 20.0, color: Color::BLACK, + ..default() }, ) .with_style(Style { diff --git a/examples/3d/atmospheric_fog.rs b/examples/3d/atmospheric_fog.rs index c61176e1b9..10082abae0 100644 --- a/examples/3d/atmospheric_fog.rs +++ b/examples/3d/atmospheric_fog.rs @@ -93,13 +93,13 @@ fn setup_terrain_scene( )); } -fn setup_instructions(mut commands: Commands, asset_server: Res) { +fn setup_instructions(mut commands: Commands) { commands.spawn((TextBundle::from_section( "Press Spacebar to Toggle Atmospheric Fog.\nPress S to Toggle Directional Light Fog Influence.", TextStyle { - font: asset_server.load("fonts/FiraMono-Medium.ttf"), font_size: 15.0, color: Color::WHITE, + ..default() }, ) .with_style(Style { diff --git a/examples/3d/blend_modes.rs b/examples/3d/blend_modes.rs index 1fa14e8e8f..262728dbfc 100644 --- a/examples/3d/blend_modes.rs +++ b/examples/3d/blend_modes.rs @@ -34,7 +34,6 @@ fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, - asset_server: Res, ) { let base_color = Color::rgba(0.9, 0.2, 0.3, 1.0); let icosphere_mesh = meshes.add( @@ -186,15 +185,15 @@ fn setup( // Controls Text let text_style = TextStyle { - font: asset_server.load("fonts/FiraMono-Medium.ttf"), font_size: 18.0, color: Color::BLACK, + ..default() }; let label_text_style = TextStyle { - font: asset_server.load("fonts/FiraMono-Medium.ttf"), font_size: 25.0, color: Color::ORANGE, + ..default() }; commands.spawn( diff --git a/examples/3d/bloom_3d.rs b/examples/3d/bloom_3d.rs index b59fb59177..057df68d1d 100644 --- a/examples/3d/bloom_3d.rs +++ b/examples/3d/bloom_3d.rs @@ -25,7 +25,6 @@ fn setup_scene( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, - asset_server: Res, ) { commands.spawn(( Camera3dBundle { @@ -96,9 +95,9 @@ fn setup_scene( TextBundle::from_section( "", TextStyle { - font: asset_server.load("fonts/FiraMono-Medium.ttf"), font_size: 18.0, color: Color::BLACK, + ..default() }, ) .with_style(Style { diff --git a/examples/3d/fog.rs b/examples/3d/fog.rs index bfad6400dd..21500cbe71 100644 --- a/examples/3d/fog.rs +++ b/examples/3d/fog.rs @@ -137,13 +137,13 @@ fn setup_pyramid_scene( }); } -fn setup_instructions(mut commands: Commands, asset_server: Res) { +fn setup_instructions(mut commands: Commands) { commands.spawn((TextBundle::from_section( "", TextStyle { - font: asset_server.load("fonts/FiraMono-Medium.ttf"), font_size: 15.0, color: Color::WHITE, + ..default() }, ) .with_style(Style { diff --git a/examples/3d/parallax_mapping.rs b/examples/3d/parallax_mapping.rs index 16a893260a..c8f2585e6c 100644 --- a/examples/3d/parallax_mapping.rs +++ b/examples/3d/parallax_mapping.rs @@ -315,9 +315,9 @@ fn setup( commands.spawn(background_cube_bundle(Vec3::new(0., 0., -45.))); let style = TextStyle { - font: asset_server.load("fonts/FiraMono-Medium.ttf"), font_size: 18.0, color: Color::WHITE, + ..default() }; commands.spawn( diff --git a/examples/3d/pbr.rs b/examples/3d/pbr.rs index e5d41eccf9..a1f01106cd 100644 --- a/examples/3d/pbr.rs +++ b/examples/3d/pbr.rs @@ -78,9 +78,9 @@ fn setup( TextBundle::from_section( "Perceptual Roughness", TextStyle { - font: asset_server.load("fonts/FiraMono-Medium.ttf"), font_size: 36.0, color: Color::WHITE, + ..default() }, ) .with_style(Style { @@ -95,9 +95,9 @@ fn setup( text: Text::from_section( "Metallic", TextStyle { - font: asset_server.load("fonts/FiraMono-Medium.ttf"), font_size: 36.0, color: Color::WHITE, + ..default() }, ), style: Style { @@ -117,9 +117,9 @@ fn setup( TextBundle::from_section( "Loading Environment Map...", TextStyle { - font: asset_server.load("fonts/FiraMono-Medium.ttf"), font_size: 36.0, color: Color::RED, + ..default() }, ) .with_style(Style { diff --git a/examples/3d/tonemapping.rs b/examples/3d/tonemapping.rs index 946f5ab859..482d2bd182 100644 --- a/examples/3d/tonemapping.rs +++ b/examples/3d/tonemapping.rs @@ -75,9 +75,9 @@ fn setup( TextBundle::from_section( "", TextStyle { - font: asset_server.load("fonts/FiraMono-Medium.ttf"), font_size: 18.0, color: Color::WHITE, + ..default() }, ) .with_style(Style { @@ -243,7 +243,6 @@ fn setup_image_viewer_scene( mut meshes: ResMut>, mut materials: ResMut>, camera_transform: Res, - asset_server: Res, ) { let mut transform = camera_transform.0; transform.translation += transform.forward(); @@ -273,9 +272,9 @@ fn setup_image_viewer_scene( TextBundle::from_section( "Drag and drop an HDR or EXR file", TextStyle { - font: asset_server.load("fonts/FiraMono-Medium.ttf"), font_size: 36.0, color: Color::BLACK, + ..default() }, ) .with_text_alignment(TextAlignment::Center) diff --git a/examples/async_tasks/external_source_external_thread.rs b/examples/async_tasks/external_source_external_thread.rs index 173420ca60..57a403ef29 100644 --- a/examples/async_tasks/external_source_external_thread.rs +++ b/examples/async_tasks/external_source_external_thread.rs @@ -19,10 +19,7 @@ fn main() { struct StreamReceiver(Receiver); struct StreamEvent(u32); -#[derive(Resource, Deref)] -struct LoadedFont(Handle); - -fn setup(mut commands: Commands, asset_server: Res) { +fn setup(mut commands: Commands) { commands.spawn(Camera2dBundle::default()); let (tx, rx) = bounded::(10); @@ -40,7 +37,6 @@ fn setup(mut commands: Commands, asset_server: Res) { }); commands.insert_resource(StreamReceiver(rx)); - commands.insert_resource(LoadedFont(asset_server.load("fonts/FiraSans-Bold.ttf"))); } // This system reads from the receiver and sends events to Bevy @@ -50,15 +46,11 @@ fn read_stream(receiver: Res, mut events: EventWriter, - loaded_font: Res, -) { +fn spawn_text(mut commands: Commands, mut reader: EventReader) { let text_style = TextStyle { - font: loaded_font.clone(), font_size: 20.0, color: Color::WHITE, + ..default() }; for (per_frame, event) in reader.iter().enumerate() { diff --git a/examples/ecs/apply_system_buffers.rs b/examples/ecs/apply_system_buffers.rs index b9a2053ec6..893dc71cd5 100644 --- a/examples/ecs/apply_system_buffers.rs +++ b/examples/ecs/apply_system_buffers.rs @@ -63,7 +63,7 @@ struct AppleCount; struct OrangeCount; // Setup the counters in the UI. -fn setup(mut commands: Commands, asset_server: Res) { +fn setup(mut commands: Commands) { commands.spawn(Camera2dBundle::default()); commands @@ -82,9 +82,9 @@ fn setup(mut commands: Commands, asset_server: Res) { TextBundle::from_section( "Apple: nothing counted yet".to_string(), TextStyle { - font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 80.0, color: Color::ORANGE, + ..default() }, ), AppleCount, @@ -93,9 +93,9 @@ fn setup(mut commands: Commands, asset_server: Res) { TextBundle::from_section( "Orange: nothing counted yet".to_string(), TextStyle { - font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 80.0, color: Color::ORANGE, + ..default() }, ), OrangeCount, diff --git a/examples/ecs/state.rs b/examples/ecs/state.rs index 76869db18e..af4da80d18 100644 --- a/examples/ecs/state.rs +++ b/examples/ecs/state.rs @@ -48,7 +48,7 @@ fn setup(mut commands: Commands) { commands.spawn(Camera2dBundle::default()); } -fn setup_menu(mut commands: Commands, asset_server: Res) { +fn setup_menu(mut commands: Commands) { let button_entity = commands .spawn(NodeBundle { style: Style { @@ -78,9 +78,9 @@ fn setup_menu(mut commands: Commands, asset_server: Res) { parent.spawn(TextBundle::from_section( "Play", TextStyle { - font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 40.0, color: Color::rgb(0.9, 0.9, 0.9), + ..default() }, )); }); diff --git a/examples/games/alien_cake_addict.rs b/examples/games/alien_cake_addict.rs index 6726108435..a61c4f3e12 100644 --- a/examples/games/alien_cake_addict.rs +++ b/examples/games/alien_cake_addict.rs @@ -168,9 +168,9 @@ fn setup(mut commands: Commands, asset_server: Res, mut game: ResMu TextBundle::from_section( "Score:", TextStyle { - font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 40.0, color: Color::rgb(0.5, 0.5, 1.0), + ..default() }, ) .with_style(Style { @@ -384,7 +384,7 @@ fn gameover_keyboard( } // display the number of cake eaten before losing -fn display_score(mut commands: Commands, asset_server: Res, game: Res) { +fn display_score(mut commands: Commands, game: Res) { commands .spawn(NodeBundle { style: Style { @@ -399,9 +399,9 @@ fn display_score(mut commands: Commands, asset_server: Res, game: R parent.spawn(TextBundle::from_section( format!("Cake eaten: {}", game.cake_eaten), TextStyle { - font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 80.0, color: Color::rgb(0.5, 0.5, 1.0), + ..default() }, )); }); diff --git a/examples/games/breakout.rs b/examples/games/breakout.rs index a10b194edb..577b5fe681 100644 --- a/examples/games/breakout.rs +++ b/examples/games/breakout.rs @@ -223,15 +223,15 @@ fn setup( TextSection::new( "Score: ", TextStyle { - font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: SCOREBOARD_FONT_SIZE, color: TEXT_COLOR, + ..default() }, ), TextSection::from_style(TextStyle { - font: asset_server.load("fonts/FiraMono-Medium.ttf"), font_size: SCOREBOARD_FONT_SIZE, color: SCORE_COLOR, + ..default() }), ]) .with_style(Style { diff --git a/examples/games/game_menu.rs b/examples/games/game_menu.rs index 0ba535928c..ff39d23d44 100644 --- a/examples/games/game_menu.rs +++ b/examples/games/game_menu.rs @@ -145,12 +145,9 @@ mod game { fn game_setup( mut commands: Commands, - asset_server: Res, display_quality: Res, volume: Res, ) { - let font = asset_server.load("fonts/FiraSans-Bold.ttf"); - commands .spawn(( NodeBundle { @@ -187,9 +184,9 @@ mod game { TextBundle::from_section( "Will be back to the menu shortly...", TextStyle { - font: font.clone(), font_size: 80.0, color: TEXT_COLOR, + ..default() }, ) .with_style(Style { @@ -202,25 +199,25 @@ mod game { TextSection::new( format!("quality: {:?}", *display_quality), TextStyle { - font: font.clone(), font_size: 60.0, color: Color::BLUE, + ..default() }, ), TextSection::new( " - ", TextStyle { - font: font.clone(), font_size: 60.0, color: TEXT_COLOR, + ..default() }, ), TextSection::new( format!("volume: {:?}", *volume), TextStyle { - font: font.clone(), font_size: 60.0, color: Color::GREEN, + ..default() }, ), ]) @@ -398,7 +395,6 @@ mod menu { } fn main_menu_setup(mut commands: Commands, asset_server: Res) { - let font = asset_server.load("fonts/FiraSans-Bold.ttf"); // Common style for all buttons on the screen let button_style = Style { size: Size::new(Val::Px(250.0), Val::Px(65.0)), @@ -417,9 +413,9 @@ mod menu { ..default() }; let button_text_style = TextStyle { - font: font.clone(), font_size: 40.0, color: TEXT_COLOR, + ..default() }; commands @@ -452,9 +448,9 @@ mod menu { TextBundle::from_section( "Bevy Game Menu UI", TextStyle { - font: font.clone(), font_size: 80.0, color: TEXT_COLOR, + ..default() }, ) .with_style(Style { @@ -531,7 +527,7 @@ mod menu { }); } - fn settings_menu_setup(mut commands: Commands, asset_server: Res) { + fn settings_menu_setup(mut commands: Commands) { let button_style = Style { size: Size::new(Val::Px(200.0), Val::Px(65.0)), margin: UiRect::all(Val::Px(20.0)), @@ -541,9 +537,9 @@ mod menu { }; let button_text_style = TextStyle { - font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 40.0, color: TEXT_COLOR, + ..default() }; commands @@ -596,11 +592,7 @@ mod menu { }); } - fn display_settings_menu_setup( - mut commands: Commands, - asset_server: Res, - display_quality: Res, - ) { + fn display_settings_menu_setup(mut commands: Commands, display_quality: Res) { let button_style = Style { size: Size::new(Val::Px(200.0), Val::Px(65.0)), margin: UiRect::all(Val::Px(20.0)), @@ -609,9 +601,9 @@ mod menu { ..default() }; let button_text_style = TextStyle { - font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 40.0, color: TEXT_COLOR, + ..default() }; commands @@ -698,11 +690,7 @@ mod menu { }); } - fn sound_settings_menu_setup( - mut commands: Commands, - asset_server: Res, - volume: Res, - ) { + fn sound_settings_menu_setup(mut commands: Commands, volume: Res) { let button_style = Style { size: Size::new(Val::Px(200.0), Val::Px(65.0)), margin: UiRect::all(Val::Px(20.0)), @@ -711,9 +699,9 @@ mod menu { ..default() }; let button_text_style = TextStyle { - font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 40.0, color: TEXT_COLOR, + ..default() }; commands diff --git a/examples/mobile/src/lib.rs b/examples/mobile/src/lib.rs index 052e363d90..843b5cb539 100644 --- a/examples/mobile/src/lib.rs +++ b/examples/mobile/src/lib.rs @@ -55,7 +55,6 @@ fn setup_scene( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, - asset_server: Res, ) { // plane commands.spawn(PbrBundle { @@ -122,9 +121,9 @@ fn setup_scene( TextBundle::from_section( "Test Button", TextStyle { - font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 30.0, color: Color::BLACK, + ..default() }, ) .with_text_alignment(TextAlignment::Center), diff --git a/examples/scene/scene.rs b/examples/scene/scene.rs index e066ba6207..537d669e7b 100644 --- a/examples/scene/scene.rs +++ b/examples/scene/scene.rs @@ -140,15 +140,15 @@ fn save_scene_system(world: &mut World) { // This is only necessary for the info message in the UI. See examples/ui/text.rs for a standalone // text example. -fn infotext_system(mut commands: Commands, asset_server: Res) { +fn infotext_system(mut commands: Commands) { commands.spawn(Camera2dBundle::default()); commands.spawn( TextBundle::from_section( "Nothing to see in this window! Check the console output!", TextStyle { - font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 50.0, color: Color::WHITE, + ..default() }, ) .with_style(Style { diff --git a/examples/shader/shader_prepass.rs b/examples/shader/shader_prepass.rs index 5d34f44b0a..f333b00384 100644 --- a/examples/shader/shader_prepass.rs +++ b/examples/shader/shader_prepass.rs @@ -126,9 +126,9 @@ fn setup( }); let style = TextStyle { - font: asset_server.load("fonts/FiraMono-Medium.ttf"), font_size: 18.0, color: Color::WHITE, + ..default() }; commands.spawn( diff --git a/examples/stress_tests/bevymark.rs b/examples/stress_tests/bevymark.rs index 83c1abfa56..4518b804e7 100644 --- a/examples/stress_tests/bevymark.rs +++ b/examples/stress_tests/bevymark.rs @@ -103,9 +103,9 @@ fn setup(mut commands: Commands, asset_server: Res) { TextSection::new( value, TextStyle { - font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 40.0, color, + ..default() }, ) }; diff --git a/examples/stress_tests/many_buttons.rs b/examples/stress_tests/many_buttons.rs index 2b177c16d4..139e4d7340 100644 --- a/examples/stress_tests/many_buttons.rs +++ b/examples/stress_tests/many_buttons.rs @@ -32,7 +32,6 @@ fn main() { })) .add_plugin(FrameTimeDiagnosticsPlugin::default()) .add_plugin(LogDiagnosticsPlugin::default()) - .init_resource::() .add_systems(Startup, setup) .add_systems(Update, button_system); @@ -69,17 +68,7 @@ fn button_system( } } -#[derive(Resource)] -struct UiFont(Handle); - -impl FromWorld for UiFont { - fn from_world(world: &mut World) -> Self { - let asset_server = world.resource::(); - UiFont(asset_server.load("fonts/FiraSans-Bold.ttf")) - } -} - -fn setup(mut commands: Commands, font: Res) { +fn setup(mut commands: Commands) { let count = ROW_COLUMN_COUNT; let count_f = count as f32; let as_rainbow = |i: usize| Color::hsl((i as f32 / count_f) * 360.0, 0.9, 0.8); @@ -97,15 +86,7 @@ fn setup(mut commands: Commands, font: Res) { for i in 0..count { for j in 0..count { let color = as_rainbow(j % i.max(1)).into(); - spawn_button( - commands, - font.0.clone_weak(), - color, - count_f, - i, - j, - spawn_text, - ); + spawn_button(commands, color, count_f, i, j, spawn_text); } } }); @@ -113,7 +94,6 @@ fn setup(mut commands: Commands, font: Res) { fn spawn_button( commands: &mut ChildBuilder, - font: Handle, color: BackgroundColor, total: f32, i: usize, @@ -142,9 +122,9 @@ fn spawn_button( commands.spawn(TextBundle::from_section( format!("{i}, {j}"), TextStyle { - font, font_size: FONT_SIZE, color: Color::rgb(0.2, 0.2, 0.2), + ..default() }, )); }); diff --git a/examples/stress_tests/many_gizmos.rs b/examples/stress_tests/many_gizmos.rs index 5d7350a22d..817a2e8aae 100644 --- a/examples/stress_tests/many_gizmos.rs +++ b/examples/stress_tests/many_gizmos.rs @@ -73,7 +73,7 @@ fn system(config: Res, time: Res