Skip to content

Commit

Permalink
remove toggling overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
matiqo15 committed Mar 8, 2024
1 parent e0a3bec commit ede91b8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 40 deletions.
32 changes: 2 additions & 30 deletions crates/bevy_dev_tools/src/fps_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use bevy_ecs::{
schedule::{common_conditions::resource_changed, IntoSystemConfigs},
system::{Commands, Query, Res, Resource},
};
use bevy_input::{keyboard::KeyCode, ButtonInput};
use bevy_render::view::Visibility;
use bevy_text::{Text, TextSection, TextStyle};
use bevy_ui::node_bundles::TextBundle;

Expand All @@ -32,7 +30,6 @@ impl Plugin for FpsOverlayPlugin {
(
customize_text.run_if(resource_changed::<FpsOverlayConfig>),
update_text,
toggle_overlay,
),
);
}
Expand All @@ -48,8 +45,6 @@ pub struct FpsOverlayConfig {
pub font_size: f32,
/// Color of the overlay text.
pub font_color: Color,
/// Keybind for toggling on/off the overlay.
pub keybind: KeyCode,
}

impl Default for FpsOverlayConfig {
Expand All @@ -58,7 +53,6 @@ impl Default for FpsOverlayConfig {
font_path: None,
font_size: 32.0,
font_color: Color::WHITE,
keybind: KeyCode::F1,
}
}
}
Expand Down Expand Up @@ -107,14 +101,8 @@ fn setup(
));
}

fn update_text(
diagnostic: Res<DiagnosticsStore>,
mut query: Query<(&mut Text, &Visibility), With<FpsText>>,
) {
for (mut text, visibility) in &mut query {
if let Visibility::Hidden = *visibility {
return;
}
fn update_text(diagnostic: Res<DiagnosticsStore>, mut query: Query<&mut Text, With<FpsText>>) {
for mut text in &mut query {
if let Some(fps) = diagnostic.get(&FrameTimeDiagnosticsPlugin::FPS) {
if let Some(value) = fps.smoothed() {
text.sections[1].value = format!("{value:.2}");
Expand Down Expand Up @@ -146,19 +134,3 @@ fn customize_text(
}
}
}

fn toggle_overlay(
input: Res<ButtonInput<KeyCode>>,
mut query: Query<&mut Visibility, With<FpsText>>,
overlay_config: Res<FpsOverlayConfig>,
) {
if input.just_pressed(overlay_config.keybind) {
for mut visibility in query.iter_mut() {
*visibility = if let Visibility::Hidden = *visibility {
Visibility::Visible
} else {
Visibility::Hidden
}
}
}
}
11 changes: 1 addition & 10 deletions examples/dev_tools/fps_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ fn main() {
font_color: Color::srgb(0.0, 1.0, 0.0),
// If we want, we can use a custom font
font_path: None,
// This keybind will be toggling on/off the overlay
keybind: KeyCode::Escape,
},
},
))
Expand All @@ -33,14 +31,7 @@ fn setup(mut commands: Commands) {
commands.spawn(
TextBundle::from_sections([
TextSection::new(
"Press ESC to toggle overlay",
TextStyle {
font_size: 25.0,
..default()
},
),
TextSection::new(
"\nPress 1 to change color of the overlay.",
"Press 1 to change color of the overlay.",
TextStyle {
font_size: 25.0,
..default()
Expand Down

0 comments on commit ede91b8

Please sign in to comment.