Skip to content

Commit

Permalink
More
Browse files Browse the repository at this point in the history
  • Loading branch information
rparrett committed May 30, 2024
1 parent 4c8bcfa commit faea034
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 88 deletions.
19 changes: 12 additions & 7 deletions examples/2d/wireframe_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,17 @@ fn setup(

// Text used to show controls
commands.spawn(
TextBundle::from_section("", TextStyle::default()).with_style(Style {
TextBundle::from_section(
"",
TextStyle {
font_size: 20.,
..default()
},
)
.with_style(Style {
position_type: PositionType::Absolute,
top: Val::Px(10.0),
left: Val::Px(10.0),
top: Val::Px(12.0),
left: Val::Px(12.0),
..default()
}),
);
Expand All @@ -116,8 +123,7 @@ fn update_colors(
mut text: Query<&mut Text>,
) {
text.single_mut().sections[0].value = format!(
"
Controls
"Controls
---------------
Z - Toggle global
X - Change global color
Expand All @@ -126,8 +132,7 @@ C - Change color of the circle wireframe
Wireframe2dConfig
-------------
Global: {}
Color: {:?}
",
Color: {:?}",
config.global, config.default_color,
);

Expand Down
10 changes: 5 additions & 5 deletions examples/3d/blend_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fn setup(
// Controls Text
let text_style = TextStyle {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: 18.0,
font_size: 20.0,
..default()
};

Expand All @@ -198,17 +198,17 @@ fn setup(
)
.with_style(Style {
position_type: PositionType::Absolute,
top: Val::Px(10.0),
left: Val::Px(10.0),
top: Val::Px(12.0),
left: Val::Px(12.0),
..default()
}),
);

commands.spawn((
TextBundle::from_section("", text_style).with_style(Style {
position_type: PositionType::Absolute,
top: Val::Px(10.0),
right: Val::Px(10.0),
top: Val::Px(12.0),
right: Val::Px(12.0),
..default()
}),
ExampleDisplay,
Expand Down
23 changes: 9 additions & 14 deletions examples/3d/clearcoat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn setup(

spawn_light(&mut commands);
spawn_camera(&mut commands, &asset_server);
spawn_text(&mut commands, &asset_server, &light_mode);
spawn_text(&mut commands, &light_mode);
}

/// Generates a sphere.
Expand Down Expand Up @@ -232,16 +232,16 @@ fn spawn_camera(commands: &mut Commands, asset_server: &AssetServer) {
}

/// Spawns the help text.
fn spawn_text(commands: &mut Commands, asset_server: &AssetServer, light_mode: &LightMode) {
fn spawn_text(commands: &mut Commands, light_mode: &LightMode) {
commands.spawn(
TextBundle {
text: light_mode.create_help_text(asset_server),
text: light_mode.create_help_text(),
..TextBundle::default()
}
.with_style(Style {
position_type: PositionType::Absolute,
bottom: Val::Px(10.0),
left: Val::Px(10.0),
bottom: Val::Px(12.0),
left: Val::Px(12.0),
..default()
}),
);
Expand Down Expand Up @@ -304,13 +304,9 @@ fn handle_input(
}

/// Updates the help text at the bottom of the screen.
fn update_help_text(
mut text_query: Query<&mut Text>,
light_mode: Res<LightMode>,
asset_server: Res<AssetServer>,
) {
fn update_help_text(mut text_query: Query<&mut Text>, light_mode: Res<LightMode>) {
for mut text in text_query.iter_mut() {
*text = light_mode.create_help_text(&asset_server);
*text = light_mode.create_help_text();
}
}

Expand All @@ -334,7 +330,7 @@ fn create_directional_light() -> DirectionalLight {

impl LightMode {
/// Creates the help text at the bottom of the screen.
fn create_help_text(&self, asset_server: &AssetServer) -> Text {
fn create_help_text(&self) -> Text {
let help_text = match *self {
LightMode::Point => "Press Space to switch to a directional light",
LightMode::Directional => "Press Space to switch to a point light",
Expand All @@ -343,8 +339,7 @@ impl LightMode {
Text::from_section(
help_text,
TextStyle {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: 24.0,
font_size: 20.0,
..default()
},
)
Expand Down
19 changes: 7 additions & 12 deletions examples/3d/depth_of_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, app_settings: R
// Spawn the help text.
commands.spawn(
TextBundle {
text: create_text(&asset_server, &app_settings),
text: create_text(&app_settings),
..TextBundle::default()
}
.with_style(Style {
position_type: PositionType::Absolute,
bottom: Val::Px(10.0),
left: Val::Px(10.0),
bottom: Val::Px(12.0),
left: Val::Px(12.0),
..default()
}),
);
Expand Down Expand Up @@ -212,23 +212,18 @@ fn tweak_scene(
}

/// Update the help text entity per the current app settings.
fn update_text(
mut texts: Query<&mut Text>,
asset_server: Res<AssetServer>,
app_settings: Res<AppSettings>,
) {
fn update_text(mut texts: Query<&mut Text>, app_settings: Res<AppSettings>) {
for mut text in texts.iter_mut() {
*text = create_text(&asset_server, &app_settings);
*text = create_text(&app_settings);
}
}

/// Regenerates the app text component per the current app settings.
fn create_text(asset_server: &AssetServer, app_settings: &AppSettings) -> Text {
fn create_text(app_settings: &AppSettings) -> Text {
Text::from_section(
app_settings.help_text(),
TextStyle {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: 24.0,
font_size: 20.0,
..default()
},
)
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/motion_blur.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ fn spawn_trees(

fn setup_ui(mut commands: Commands) {
let style = TextStyle {
font_size: 24.0,
font_size: 20.0,
..default()
};
commands.spawn(
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/reflection_probes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ fn spawn_text(commands: &mut Commands, app_status: &AppStatus) {
commands.spawn(
TextBundle {
text: app_status.create_text(),
..TextBundle::default()
..default()
}
.with_style(Style {
position_type: PositionType::Absolute,
Expand Down
6 changes: 3 additions & 3 deletions examples/3d/ssao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ fn setup(
"",
TextStyle {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: 26.0,
font_size: 20.0,
..default()
},
)
.with_style(Style {
position_type: PositionType::Absolute,
bottom: Val::Px(10.0),
left: Val::Px(10.0),
bottom: Val::Px(12.0),
left: Val::Px(12.0),
..default()
}),
);
Expand Down
18 changes: 8 additions & 10 deletions examples/3d/ssr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn setup(
&mut water_materials,
);
spawn_camera(&mut commands, &asset_server);
spawn_text(&mut commands, &asset_server, &app_settings);
spawn_text(&mut commands, &app_settings);
}

// Spawns the rotating cube.
Expand Down Expand Up @@ -248,23 +248,23 @@ fn spawn_camera(commands: &mut Commands, asset_server: &AssetServer) {
}

// Spawns the help text.
fn spawn_text(commands: &mut Commands, asset_server: &AssetServer, app_settings: &AppSettings) {
fn spawn_text(commands: &mut Commands, app_settings: &AppSettings) {
commands.spawn(
TextBundle {
text: create_text(asset_server, app_settings),
text: create_text(app_settings),
..TextBundle::default()
}
.with_style(Style {
position_type: PositionType::Absolute,
bottom: Val::Px(10.0),
left: Val::Px(10.0),
bottom: Val::Px(12.0),
left: Val::Px(12.0),
..default()
}),
);
}

// Creates or recreates the help text.
fn create_text(asset_server: &AssetServer, app_settings: &AppSettings) -> Text {
fn create_text(app_settings: &AppSettings) -> Text {
Text::from_section(
format!(
"{}\n{}\n{}",
Expand All @@ -280,8 +280,7 @@ fn create_text(asset_server: &AssetServer, app_settings: &AppSettings) -> Text {
MOVE_CAMERA_HELP_TEXT
),
TextStyle {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: 24.0,
font_size: 20.0,
..default()
},
)
Expand Down Expand Up @@ -350,7 +349,6 @@ fn move_camera(
#[allow(clippy::too_many_arguments)]
fn adjust_app_settings(
mut commands: Commands,
asset_server: Res<AssetServer>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut app_settings: ResMut<AppSettings>,
mut cameras: Query<Entity, With<Camera>>,
Expand Down Expand Up @@ -413,7 +411,7 @@ fn adjust_app_settings(

// Update the help text.
for mut text in text.iter_mut() {
*text = create_text(&asset_server, &app_settings);
*text = create_text(&app_settings);
}
}

Expand Down
6 changes: 3 additions & 3 deletions examples/3d/tonemapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ fn setup(
TextBundle::from_section(
"",
TextStyle {
font_size: 18.0,
font_size: 20.0,
..default()
},
)
.with_style(Style {
position_type: PositionType::Absolute,
top: Val::Px(10.0),
left: Val::Px(10.0),
top: Val::Px(12.0),
left: Val::Px(12.0),
..default()
}),
);
Expand Down
6 changes: 3 additions & 3 deletions examples/3d/transmission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,15 @@ fn setup(

// Controls Text
let text_style = TextStyle {
font_size: 18.0,
font_size: 20.0,
..default()
};

commands.spawn((
TextBundle::from_section("", text_style).with_style(Style {
position_type: PositionType::Absolute,
top: Val::Px(10.0),
left: Val::Px(10.0),
top: Val::Px(12.0),
left: Val::Px(12.0),
..default()
}),
ExampleDisplay,
Expand Down
19 changes: 7 additions & 12 deletions examples/3d/visibility_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ fn setup(
// Create the text.
commands.spawn(
TextBundle {
text: app_status.create_text(&asset_server),
text: app_status.create_text(),
..TextBundle::default()
}
.with_style(Style {
position_type: PositionType::Absolute,
bottom: Val::Px(10.0),
left: Val::Px(10.0),
bottom: Val::Px(12.0),
left: Val::Px(12.0),
..default()
}),
);
Expand Down Expand Up @@ -290,19 +290,15 @@ fn update_mode(
}

// A system that updates the help text.
fn update_help_text(
mut text_query: Query<&mut Text>,
app_status: Res<AppStatus>,
asset_server: Res<AssetServer>,
) {
fn update_help_text(mut text_query: Query<&mut Text>, app_status: Res<AppStatus>) {
for mut text in text_query.iter_mut() {
*text = app_status.create_text(&asset_server);
*text = app_status.create_text();
}
}

impl AppStatus {
// Creates and returns help text reflecting the app status.
fn create_text(&self, asset_server: &AssetServer) -> Text {
fn create_text(&self) -> Text {
Text::from_section(
format!(
"\
Expand All @@ -328,8 +324,7 @@ Press WASD or use the mouse wheel to move the camera",
},
),
TextStyle {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: 24.0,
font_size: 20.0,
..default()
},
)
Expand Down
7 changes: 3 additions & 4 deletions examples/3d/volumetric_fog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,16 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
text: Text::from_section(
"Press WASD or the arrow keys to change the light direction",
TextStyle {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: 24.0,
font_size: 20.0,
..default()
},
),
..default()
}
.with_style(Style {
position_type: PositionType::Absolute,
bottom: Val::Px(10.0),
left: Val::Px(10.0),
top: Val::Px(12.0),
left: Val::Px(12.0),
..default()
}),
);
Expand Down
Loading

0 comments on commit faea034

Please sign in to comment.