From 38430d9b823a719b9170c4a0ccffaed80f2319bd Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 30 Aug 2023 23:06:57 +0100 Subject: [PATCH] Fix a bunch of examples --- examples/ecs/apply_deferred.rs | 1 + examples/ecs/state.rs | 1 + examples/games/game_menu.rs | 4 + examples/stress_tests/many_buttons.rs | 1 + examples/stress_tests/many_glyphs.rs | 2 +- examples/ui/borders.rs | 3 +- examples/ui/button.rs | 1 + examples/ui/display_and_visibility.rs | 6 +- examples/ui/overflow.rs | 3 +- examples/ui/size_constraints.rs | 3 +- examples/ui/text.rs | 98 ++++++----- examples/ui/text_debug.rs | 214 ++++++++++++----------- examples/ui/text_wrap_debug.rs | 3 +- examples/ui/transparency_ui.rs | 1 + examples/ui/ui_texture_atlas.rs | 3 +- examples/ui/z_index.rs | 1 + examples/window/scale_factor_override.rs | 1 + 17 files changed, 191 insertions(+), 155 deletions(-) diff --git a/examples/ecs/apply_deferred.rs b/examples/ecs/apply_deferred.rs index e9944e497ffd9..a8ffaad2bb853 100644 --- a/examples/ecs/apply_deferred.rs +++ b/examples/ecs/apply_deferred.rs @@ -70,6 +70,7 @@ fn setup(mut commands: Commands) { .spawn(NodeBundle { style: Style { width: Val::Percent(100.0), + height: Val::Percent(100.0), align_items: AlignItems::Center, justify_content: JustifyContent::Center, flex_direction: FlexDirection::Column, diff --git a/examples/ecs/state.rs b/examples/ecs/state.rs index 31c0346206bdb..c4603196f461b 100644 --- a/examples/ecs/state.rs +++ b/examples/ecs/state.rs @@ -54,6 +54,7 @@ fn setup_menu(mut commands: Commands) { style: Style { // center button width: Val::Percent(100.), + height: Val::Percent(100.), justify_content: JustifyContent::Center, align_items: AlignItems::Center, ..default() diff --git a/examples/games/game_menu.rs b/examples/games/game_menu.rs index 092c2ef0d8789..db45f4c3182b1 100644 --- a/examples/games/game_menu.rs +++ b/examples/games/game_menu.rs @@ -423,6 +423,7 @@ mod menu { NodeBundle { style: Style { width: Val::Percent(100.0), + height: Val::Percent(100.0), align_items: AlignItems::Center, justify_content: JustifyContent::Center, ..default() @@ -548,6 +549,7 @@ mod menu { NodeBundle { style: Style { width: Val::Percent(100.0), + height: Val::Percent(100.0), align_items: AlignItems::Center, justify_content: JustifyContent::Center, ..default() @@ -613,6 +615,7 @@ mod menu { NodeBundle { style: Style { width: Val::Percent(100.0), + height: Val::Percent(100.0), align_items: AlignItems::Center, justify_content: JustifyContent::Center, ..default() @@ -713,6 +716,7 @@ mod menu { NodeBundle { style: Style { width: Val::Percent(100.0), + height: Val::Percent(100.0), align_items: AlignItems::Center, justify_content: JustifyContent::Center, ..default() diff --git a/examples/stress_tests/many_buttons.rs b/examples/stress_tests/many_buttons.rs index 9cd125ac0d0dc..19be31d8a5720 100644 --- a/examples/stress_tests/many_buttons.rs +++ b/examples/stress_tests/many_buttons.rs @@ -84,6 +84,7 @@ fn setup(mut commands: Commands) { .spawn(NodeBundle { style: Style { width: Val::Percent(100.), + height: Val::Percent(100.), ..default() }, ..default() diff --git a/examples/stress_tests/many_glyphs.rs b/examples/stress_tests/many_glyphs.rs index 0b095c170bee7..398ac3cb64f9b 100644 --- a/examples/stress_tests/many_glyphs.rs +++ b/examples/stress_tests/many_glyphs.rs @@ -54,7 +54,7 @@ fn setup(mut commands: Commands) { commands .spawn(NodeBundle { style: Style { - flex_basis: Val::Percent(100.), + width: Val::Percent(100.), align_items: AlignItems::Center, justify_content: JustifyContent::Center, ..default() diff --git a/examples/ui/borders.rs b/examples/ui/borders.rs index bf6cac544ce75..56d18827c583f 100644 --- a/examples/ui/borders.rs +++ b/examples/ui/borders.rs @@ -14,8 +14,7 @@ fn setup(mut commands: Commands) { let root = commands .spawn(NodeBundle { style: Style { - flex_basis: Val::Percent(100.0), - margin: UiRect::all(Val::Px(25.0)), + width: Val::Percent(100.0), flex_wrap: FlexWrap::Wrap, justify_content: JustifyContent::FlexStart, align_items: AlignItems::FlexStart, diff --git a/examples/ui/button.rs b/examples/ui/button.rs index fef128f6f8c57..27ab4a19a12d5 100644 --- a/examples/ui/button.rs +++ b/examples/ui/button.rs @@ -58,6 +58,7 @@ fn setup(mut commands: Commands, asset_server: Res) { .spawn(NodeBundle { style: Style { width: Val::Percent(100.0), + height: Val::Percent(100.0), align_items: AlignItems::Center, justify_content: JustifyContent::Center, ..default() diff --git a/examples/ui/display_and_visibility.rs b/examples/ui/display_and_visibility.rs index 5ed890e372675..ea6a2c2d10aca 100644 --- a/examples/ui/display_and_visibility.rs +++ b/examples/ui/display_and_visibility.rs @@ -82,8 +82,9 @@ fn setup(mut commands: Commands, asset_server: Res) { commands.spawn(Camera2dBundle::default()); commands.spawn(NodeBundle { style: Style { + width: Val::Percent(100.), + height: Val::Percent(100.), flex_direction: FlexDirection::Column, - flex_basis: Val::Percent(100.), align_items: AlignItems::Center, justify_content: JustifyContent::SpaceEvenly, ..Default::default() @@ -189,9 +190,6 @@ fn spawn_left_panel(builder: &mut ChildBuilder, palette: &[Color; 4]) -> Vec) { commands .spawn(NodeBundle { style: Style { + width: Val::Percent(100.), + height: Val::Percent(100.), align_items: AlignItems::Center, justify_content: JustifyContent::Center, - width: Val::Percent(100.), ..Default::default() }, background_color: Color::ANTIQUE_WHITE.into(), diff --git a/examples/ui/size_constraints.rs b/examples/ui/size_constraints.rs index 41a57224fc17d..0ef84c18a4847 100644 --- a/examples/ui/size_constraints.rs +++ b/examples/ui/size_constraints.rs @@ -51,7 +51,8 @@ fn setup(mut commands: Commands, asset_server: Res) { commands .spawn(NodeBundle { style: Style { - flex_basis: Val::Percent(100.0), + width: Val::Percent(100.0), + height: Val::Percent(100.0), justify_content: JustifyContent::Center, align_items: AlignItems::Center, ..Default::default() diff --git a/examples/ui/text.rs b/examples/ui/text.rs index 6db570f19c048..f12bfe210a07a 100644 --- a/examples/ui/text.rs +++ b/examples/ui/text.rs @@ -27,51 +27,63 @@ struct ColorText; fn setup(mut commands: Commands, asset_server: Res) { // UI camera commands.spawn(Camera2dBundle::default()); - // Text with one section - commands.spawn(( - // Create a TextBundle that has a Text with a single section. - TextBundle::from_section( - // 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, + + commands + .spawn(NodeBundle { + style: Style { + width: Val::Percent(100.), + height: Val::Percent(100.), + ..default() }, - ) // Set the alignment of the Text - .with_text_alignment(TextAlignment::Center) - // Set the style of the TextBundle itself. - .with_style(Style { - position_type: PositionType::Absolute, - bottom: Val::Px(5.0), - right: Val::Px(15.0), ..default() - }), - ColorText, - )); - // Text with multiple sections - commands.spawn(( - // Create a TextBundle that has a Text with a list of sections. - TextBundle::from_sections([ - 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, - }, - ), - TextSection::from_style(TextStyle { - font_size: 60.0, - color: Color::GOLD, - // If no font is specified, it will use the default font. - ..default() - }), - ]), - FpsText, - )); + }) + .with_children(|commands| { + // Text with one section + commands.spawn(( + // Create a TextBundle that has a Text with a single section. + TextBundle::from_section( + // 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, + }, + ) // Set the alignment of the Text + .with_text_alignment(TextAlignment::Center) + // Set the style of the TextBundle itself. + .with_style(Style { + position_type: PositionType::Absolute, + bottom: Val::Px(5.0), + right: Val::Px(15.0), + ..default() + }), + ColorText, + )); + // Text with multiple sections + commands.spawn(( + // Create a TextBundle that has a Text with a list of sections. + TextBundle::from_sections([ + 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, + }, + ), + TextSection::from_style(TextStyle { + font_size: 60.0, + color: Color::GOLD, + // If no font is specified, it will use the default font. + ..default() + }), + ]), + FpsText, + )); + }); } fn text_color_system(time: Res