Skip to content

Commit

Permalink
Use standard instruction text / position in various examples (#13583)
Browse files Browse the repository at this point in the history
## Objective

Use the "standard" text size / placement for the new text in these
examples.

Continuation of an effort started here:
#8478

This is definitely not comprehensive. I did the ones that were easy to
find and relatively straightforward updates. I meant to just do
`3d_shapes` and `2d_shapes`, but one thing lead to another.

## Solution

Use `font_size: 20.0`, the default (built-in) font, `Color::WHITE`
(default), and `Val::Px(12.)` from the edges of the screen.

There are a few little drive-by cleanups of defaults not being used,
etc.

## Testing

Ran the changed examples, verified that they still look reasonable.
  • Loading branch information
rparrett authored May 30, 2024
1 parent ed042e5 commit 06f733b
Show file tree
Hide file tree
Showing 25 changed files with 139 additions and 153 deletions.
6 changes: 3 additions & 3 deletions examples/2d/2d_shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ fn setup(
TextBundle::from_section(
"Press space to toggle wireframes",
TextStyle {
font_size: 24.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
7 changes: 3 additions & 4 deletions examples/2d/bloom_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,14 @@ fn setup(
TextBundle::from_section(
"",
TextStyle {
font_size: 18.0,
color: Color::WHITE,
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
11 changes: 5 additions & 6 deletions examples/2d/bounding_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn update_text(mut text: Query<&mut Text>, cur_state: Res<State<Test>>) {
let s = if **cur_state == test { "*" } else { " " };
text.push_str(&format!(" {s} {test:?} {s}\n"));
}
text.push_str("\npress Space to cycle");
text.push_str("\nPress space to cycle");
}

#[derive(Component)]
Expand Down Expand Up @@ -195,7 +195,7 @@ struct Intersects(bool);
const OFFSET_X: f32 = 125.;
const OFFSET_Y: f32 = 75.;

fn setup(mut commands: Commands, loader: Res<AssetServer>) {
fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn((
SpatialBundle {
Expand Down Expand Up @@ -270,15 +270,14 @@ fn setup(mut commands: Commands, loader: Res<AssetServer>) {
TextBundle::from_section(
"",
TextStyle {
font: loader.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
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
6 changes: 3 additions & 3 deletions examples/3d/3d_shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ fn setup(
TextBundle::from_section(
"Press space to toggle wireframes",
TextStyle {
font_size: 24.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
9 changes: 4 additions & 5 deletions examples/3d/auto_exposure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,19 @@ fn setup(
});

let text_style = TextStyle {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: 18.0,
font_size: 20.0,
..default()
};

commands.spawn(
TextBundle::from_section(
"Left / Right Rotate Camera\nC Toggle Compensation Curve\nM Toggle Metering Mask\nV Visualize Metering Mask",
"Left / Right - Rotate Camera\nC - Toggle Compensation Curve\nM - Toggle Metering Mask\nV - Visualize Metering Mask",
text_style.clone(),
)
.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
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
1 change: 0 additions & 1 deletion examples/3d/bloom_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ fn setup_scene(
"",
TextStyle {
font_size: 20.0,
color: Color::WHITE,
..default()
},
)
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
32 changes: 11 additions & 21 deletions examples/3d/irradiance_volumes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,15 @@ fn main() {
}

// Spawns all the scene objects.
fn setup(
mut commands: Commands,
assets: Res<ExampleAssets>,
app_status: Res<AppStatus>,
asset_server: Res<AssetServer>,
) {
fn setup(mut commands: Commands, assets: Res<ExampleAssets>, app_status: Res<AppStatus>) {
spawn_main_scene(&mut commands, &assets);
spawn_camera(&mut commands, &assets);
spawn_irradiance_volume(&mut commands, &assets);
spawn_light(&mut commands);
spawn_sphere(&mut commands, &assets);
spawn_voxel_cube_parent(&mut commands);
spawn_fox(&mut commands, &assets);
spawn_text(&mut commands, &app_status, &asset_server);
spawn_text(&mut commands, &app_status);
}

fn spawn_main_scene(commands: &mut Commands, assets: &ExampleAssets) {
Expand Down Expand Up @@ -301,36 +296,32 @@ fn spawn_fox(commands: &mut Commands, assets: &ExampleAssets) {
.insert(MainObject);
}

fn spawn_text(commands: &mut Commands, app_status: &AppStatus, asset_server: &AssetServer) {
fn spawn_text(commands: &mut Commands, app_status: &AppStatus) {
commands.spawn(
TextBundle {
text: app_status.create_text(asset_server),
..TextBundle::default()
text: app_status.create_text(),
..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()
}),
);
}

// A system that updates the help text.
fn update_text(
mut text_query: Query<&mut Text>,
app_status: Res<AppStatus>,
asset_server: Res<AssetServer>,
) {
fn update_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 {
// Constructs the help text at the bottom of the screen based on the
// application status.
fn create_text(&self, asset_server: &AssetServer) -> Text {
fn create_text(&self) -> Text {
let irradiance_volume_help_text = if self.irradiance_volume_present {
DISABLE_IRRADIANCE_VOLUME_HELP_TEXT
} else {
Expand Down Expand Up @@ -364,8 +355,7 @@ impl AppStatus {
switch_mesh_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
Loading

0 comments on commit 06f733b

Please sign in to comment.