mirror of
https://github.com/OMGeeky/logisim.git
synced 2026-01-21 01:21:05 +01:00
add fps counter plugin
This commit is contained in:
63
src/fps_counter.rs
Normal file
63
src/fps_counter.rs
Normal file
@@ -0,0 +1,63 @@
|
||||
use bevy::{
|
||||
dev_tools::fps_overlay::{FpsOverlayConfig, FpsOverlayPlugin},
|
||||
prelude::*,
|
||||
text::FontSmoothing,
|
||||
};
|
||||
struct OverlayColor;
|
||||
impl OverlayColor {
|
||||
const RED: Color = Color::srgb(1.0, 0.0, 0.0);
|
||||
const GREEN: Color = Color::srgb(0.0, 1.0, 0.0);
|
||||
}
|
||||
|
||||
pub struct FpsCounterPlugin;
|
||||
impl Plugin for FpsCounterPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_plugins(FpsOverlayPlugin {
|
||||
config: FpsOverlayConfig {
|
||||
text_config: TextFont {
|
||||
font_size: 42.0,
|
||||
..default()
|
||||
},
|
||||
text_color: OverlayColor::RED,
|
||||
enabled: true,
|
||||
},
|
||||
})
|
||||
.add_systems(Startup, setup)
|
||||
.add_systems(Update, customize_config);
|
||||
}
|
||||
}
|
||||
fn setup(mut commands: Commands) {
|
||||
commands.spawn((
|
||||
Text::new(concat!(
|
||||
"Press 1 to toggle the overlay color.\n",
|
||||
"Press 2 to decrease the overlay size.\n",
|
||||
"Press 3 to increase the overlay size.\n",
|
||||
"Press 4 to toggle the overlay visibility.",
|
||||
)),
|
||||
Node {
|
||||
position_type: PositionType::Absolute,
|
||||
bottom: Val::Px(12.0),
|
||||
left: Val::Px(12.0),
|
||||
..default()
|
||||
},
|
||||
));
|
||||
}
|
||||
fn customize_config(input: Res<ButtonInput<KeyCode>>, mut overlay: ResMut<FpsOverlayConfig>) {
|
||||
if input.just_pressed(KeyCode::Digit1) {
|
||||
// Changing resource will affect overlay
|
||||
if overlay.text_color == OverlayColor::GREEN {
|
||||
overlay.text_color = OverlayColor::RED;
|
||||
} else {
|
||||
overlay.text_color = OverlayColor::GREEN;
|
||||
}
|
||||
}
|
||||
if input.just_pressed(KeyCode::Digit2) {
|
||||
overlay.text_config.font_size -= 2.0;
|
||||
}
|
||||
if input.just_pressed(KeyCode::Digit3) {
|
||||
overlay.text_config.font_size += 2.0;
|
||||
}
|
||||
if input.just_pressed(KeyCode::Digit4) {
|
||||
overlay.enabled = !overlay.enabled;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
mod fps_counter;
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugins(HelloPlugin)
|
||||
.add_plugins((
|
||||
DefaultPlugins,
|
||||
fps_counter::FpsCounterPlugin,
|
||||
))
|
||||
.run();
|
||||
}
|
||||
//region first app
|
||||
|
||||
Reference in New Issue
Block a user