1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! This example illustrates how to enable and disable the FPS text in the top left hand corner
//! for a blank screen.
//!
//! Click the screen to toggle whether the diagnostic text is enabled.

use bevy::prelude::*;

use bevy_screen_diags::{ScreenDiagsState, ScreenDiagsTextPlugin};

/// Enable the plug-ins.
fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        // Include the plugin
        .add_plugins(ScreenDiagsTextPlugin)
        .add_systems(Startup, setup)
        .add_systems(Update, mouse_handler)
        .run();
}

/// Initial set-up of the camera for the blank scene.
fn setup(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());
}

/// The mouse click handler.
fn mouse_handler(
    mouse_button_input: Res<Input<MouseButton>>,
    mut diags_state: ResMut<ScreenDiagsState>,
) {
    if mouse_button_input.just_released(MouseButton::Left) {
        if diags_state.enabled() {
            diags_state.disable();
        } else {
            diags_state.enable();
        }
    }
}