-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Add more configuration options to fps overlay #21326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
61694a4
3ec38d7
661c14b
9b25441
465ca9b
2cba4c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| //! Showcase how to use and configure FPS overlay. | ||
|
|
||
| use bevy::{ | ||
| dev_tools::fps_overlay::{FpsOverlayConfig, FpsOverlayPlugin, FrameTimeGraphConfig}, | ||
| dev_tools::fps_overlay::{ | ||
| FpsOverlayConfig, FpsOverlayPlugin, FpsOverlayPositionConfig, FpsOverlayTextConfig, | ||
| FrameTimeGraphConfig, | ||
| }, | ||
| prelude::*, | ||
| text::FontSmoothing, | ||
| }; | ||
|
|
@@ -19,26 +22,42 @@ fn main() { | |
| DefaultPlugins, | ||
| FpsOverlayPlugin { | ||
| config: FpsOverlayConfig { | ||
| text_config: TextFont { | ||
| // Here we define size of our overlay | ||
| font_size: 42.0, | ||
| // If we want, we can use a custom font | ||
| font: default(), | ||
| // We could also disable font smoothing, | ||
| font_smoothing: FontSmoothing::default(), | ||
| ..default() | ||
| // Configure the fps text on the overlay | ||
| text_config: FpsOverlayTextConfig { | ||
| // Enable or disable only the fps text | ||
| enabled: true, | ||
| font: TextFont { | ||
| // Here we define size of our overlay | ||
| font_size: 42.0, | ||
| // If we want, we can use a custom font | ||
| font: default(), | ||
| // We could also disable font smoothing, | ||
| font_smoothing: FontSmoothing::default(), | ||
| ..default() | ||
| }, | ||
| // We can also change color of the overlay | ||
| color: OverlayColor::GREEN, | ||
| }, | ||
| // We can also change color of the overlay | ||
| text_color: OverlayColor::GREEN, | ||
| // We can also set the refresh interval for the FPS counter | ||
| refresh_interval: core::time::Duration::from_millis(100), | ||
| // Enable or disable the entire fps overlay | ||
| enabled: true, | ||
| frame_time_graph_config: FrameTimeGraphConfig { | ||
| graph_config: FrameTimeGraphConfig { | ||
| enabled: true, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In terms of
And then for
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might as well rename
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem with removing I'm ok with the other suggestions.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still keeps the problem of "verbosity", because Bevy uses a lot of "declaration config". Imagine that I wanna it disabled so I can enable it with hotkey later on: app.add_plugins(FpsOverlayPlugin {
config: FpsOverlayConfig {
text_config: FpsOverlayTextConfig {
enabled: false,
..default()
},
frame_time_graph_config: FrameTimeGraphConfig {
enabled: false,
..default()
},
..default()
},
});vs app.add_plugins(FpsOverlayPlugin {
config: FpsOverlayConfig {
enabled: false,
..default()
},
}); |
||
| // The minimum acceptable fps | ||
| min_fps: 30.0, | ||
| // The target fps | ||
| target_fps: 144.0, | ||
| // When the bar is low, this color will be used | ||
| min_color: LinearRgba::GREEN, | ||
| // When the bar is high, this color will be used | ||
| max_color: LinearRgba::RED, | ||
| }, | ||
| // Set custom positioning of the overlay. Defaults to top-left on the screen. | ||
| position: FpsOverlayPositionConfig { | ||
| top: px(1.0), | ||
| left: px(1.0), | ||
| ..default() | ||
| }, | ||
| }, | ||
| }, | ||
|
|
@@ -59,8 +78,9 @@ fn setup(mut commands: Commands) { | |
| "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 text visibility.\n", | ||
| "Press 5 to toggle the frame time graph." | ||
| "Press 4 to toggle the overlay visibility.\n", | ||
| "Press 5 to toggle the frame time graph.\n", | ||
| "Press 6 to toggle the text visibility.", | ||
| )), | ||
| Node { | ||
| position_type: PositionType::Absolute, | ||
|
|
@@ -74,22 +94,25 @@ fn setup(mut commands: Commands) { | |
| 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; | ||
| if overlay.text_config.color == OverlayColor::GREEN { | ||
| overlay.text_config.color = OverlayColor::RED; | ||
| } else { | ||
| overlay.text_color = OverlayColor::GREEN; | ||
| overlay.text_config.color = OverlayColor::GREEN; | ||
| } | ||
| } | ||
| if input.just_pressed(KeyCode::Digit2) { | ||
| overlay.text_config.font_size -= 2.0; | ||
| overlay.text_config.font.font_size -= 2.0; | ||
| } | ||
| if input.just_pressed(KeyCode::Digit3) { | ||
| overlay.text_config.font_size += 2.0; | ||
| overlay.text_config.font.font_size += 2.0; | ||
| } | ||
| if input.just_pressed(KeyCode::Digit4) { | ||
| overlay.enabled = !overlay.enabled; | ||
| } | ||
| if input.just_released(KeyCode::Digit5) { | ||
| overlay.frame_time_graph_config.enabled = !overlay.frame_time_graph_config.enabled; | ||
| overlay.graph_config.enabled = !overlay.graph_config.enabled; | ||
| } | ||
| if input.just_released(KeyCode::Digit6) { | ||
| overlay.text_config.enabled = !overlay.text_config.enabled; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a resource, if it's also nested inside of FpsOverlayConfig?