Remove text and more unnecessary dependencies
This commit is contained in:
parent
a1bfe669e3
commit
6108f140b6
4 changed files with 12 additions and 203 deletions
85
src/main.rs
85
src/main.rs
|
@ -49,12 +49,11 @@ fn main() {
|
|||
app.insert_resource(Time::from_hz(10.0));
|
||||
|
||||
// Setup the scene and UI, and update text in `Update`.
|
||||
app.add_systems(Startup, (setup_scene, setup_balls, setup_text))
|
||||
app.add_systems(Startup, (setup_scene, setup_balls))
|
||||
.add_systems(
|
||||
Update,
|
||||
(
|
||||
change_timestep,
|
||||
update_timestep_text,
|
||||
// Reset the scene when the 'R' key is pressed.
|
||||
reset_balls.run_if(input_pressed(KeyCode::KeyR)),
|
||||
),
|
||||
|
@ -140,79 +139,6 @@ fn reset_balls(mut commands: Commands, query: Query<Entity, With<Ball>>) {
|
|||
commands.run_system_cached(setup_balls);
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
struct TimestepText;
|
||||
|
||||
fn setup_text(mut commands: Commands) {
|
||||
let font = TextFont {
|
||||
font_size: 20.0,
|
||||
..default()
|
||||
};
|
||||
|
||||
commands
|
||||
.spawn((
|
||||
Text::new("Fixed Hz: "),
|
||||
TextColor::from(WHITE),
|
||||
font.clone(),
|
||||
Node {
|
||||
position_type: PositionType::Absolute,
|
||||
top: Val::Px(10.0),
|
||||
left: Val::Px(10.0),
|
||||
..default()
|
||||
},
|
||||
))
|
||||
.with_child((TimestepText, TextSpan::default()));
|
||||
|
||||
commands.spawn((
|
||||
Text::new("Change Timestep With Up/Down Arrow\nPress R to reset"),
|
||||
TextColor::from(WHITE),
|
||||
TextLayout::new_with_justify(JustifyText::Right),
|
||||
font.clone(),
|
||||
Node {
|
||||
position_type: PositionType::Absolute,
|
||||
top: Val::Px(10.0),
|
||||
right: Val::Px(10.0),
|
||||
..default()
|
||||
},
|
||||
));
|
||||
|
||||
commands.spawn((
|
||||
Text::new("Interpolation"),
|
||||
TextColor::from(CYAN_400),
|
||||
font.clone(),
|
||||
Node {
|
||||
position_type: PositionType::Absolute,
|
||||
top: Val::Px(50.0),
|
||||
left: Val::Px(10.0),
|
||||
..default()
|
||||
},
|
||||
));
|
||||
|
||||
commands.spawn((
|
||||
Text::new("Extrapolation"),
|
||||
TextColor::from(LIME_400),
|
||||
font.clone(),
|
||||
Node {
|
||||
position_type: PositionType::Absolute,
|
||||
top: Val::Px(75.0),
|
||||
left: Val::Px(10.0),
|
||||
..default()
|
||||
},
|
||||
));
|
||||
|
||||
commands.spawn((
|
||||
Text::new("No Interpolation"),
|
||||
TextColor::from(RED_400),
|
||||
font.clone(),
|
||||
Node {
|
||||
position_type: PositionType::Absolute,
|
||||
top: Val::Px(100.0),
|
||||
left: Val::Px(10.0),
|
||||
..default()
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
/// Changes the timestep of the simulation when the up or down arrow keys are pressed.
|
||||
fn change_timestep(mut time: ResMut<Time<Fixed>>, keyboard_input: Res<ButtonInput<KeyCode>>) {
|
||||
if keyboard_input.pressed(KeyCode::ArrowUp) {
|
||||
|
@ -224,12 +150,3 @@ fn change_timestep(mut time: ResMut<Time<Fixed>>, keyboard_input: Res<ButtonInpu
|
|||
time.set_timestep_seconds(new_timestep);
|
||||
}
|
||||
}
|
||||
|
||||
/// Updates the text with the current timestep.
|
||||
fn update_timestep_text(
|
||||
mut text: Single<&mut TextSpan, With<TimestepText>>,
|
||||
time: Res<Time<Fixed>>,
|
||||
) {
|
||||
let timestep = time.timestep().as_secs_f32().recip();
|
||||
text.0 = format!("{timestep:.2}");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue