Skip to content

Commit

Permalink
Fix a bunch of examples
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Aug 30, 2023
1 parent 599d257 commit 38430d9
Show file tree
Hide file tree
Showing 17 changed files with 191 additions and 155 deletions.
1 change: 1 addition & 0 deletions examples/ecs/apply_deferred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions examples/ecs/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions examples/games/game_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions examples/stress_tests/many_buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ fn setup(mut commands: Commands) {
.spawn(NodeBundle {
style: Style {
width: Val::Percent(100.),
height: Val::Percent(100.),
..default()
},
..default()
Expand Down
2 changes: 1 addition & 1 deletion examples/stress_tests/many_glyphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions examples/ui/borders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions examples/ui/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
.spawn(NodeBundle {
style: Style {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
Expand Down
6 changes: 2 additions & 4 deletions examples/ui/display_and_visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
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()
Expand Down Expand Up @@ -189,9 +190,6 @@ fn spawn_left_panel(builder: &mut ChildBuilder, palette: &[Color; 4]) -> Vec<Ent
.with_children(|parent| {
parent
.spawn(NodeBundle {
style: Style {
..Default::default()
},
background_color: BackgroundColor(Color::BLACK),
..Default::default()
})
Expand Down
3 changes: 2 additions & 1 deletion examples/ui/overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
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(),
Expand Down
3 changes: 2 additions & 1 deletion examples/ui/size_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
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()
Expand Down
98 changes: 55 additions & 43 deletions examples/ui/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,51 +27,63 @@ struct ColorText;
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
// 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<Time>, mut query: Query<&mut Text, With<ColorText>>) {
Expand Down
Loading

0 comments on commit 38430d9

Please sign in to comment.