summaryrefslogtreecommitdiff
path: root/src/gfx/debug_menu.rs
blob: 1f6ebf413bd84937d9eeb59f008ea9977f5ed9ae (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use super::{camera::Camera, font::Font};
use wgpu_glyph::{Section, Text};

#[derive(Default)]
pub struct DebugMenu {
    pub enabled: bool,
    pub fps: usize,
    pub blocks: usize,
    pub blocks_visible: usize,
}

impl DebugMenu {
    pub fn render(&self, bounds: (f32, f32), camera: &Camera, font: &mut Font) {
        if !self.enabled {
            return;
        }

        let mut offset = 0.0;

        let mut add_text = |txt: &str| {
            offset += 2.0;

            font.add(Section {
                screen_position: (2.0, offset),
                bounds,
                text: vec![Text::new(txt)
                    .with_color([1.0, 1.0, 1.0, 1.0])
                    .with_scale(20.0)],
                ..Section::default()
            });

            offset += 20.0;
        };

        add_text(&format!(
            "{} {}",
            env!("CARGO_PKG_NAME"),
            env!("CARGO_PKG_VERSION")
        ));
        add_text(&format!("{} FPS", self.fps));
        add_text(&format!(
            "({:.1}, {:.1}, {:.1})",
            camera.pos.x, camera.pos.y, camera.pos.z
        ));
        add_text(&format!("yaw: {:.1}°", (camera.rot.y.0 + 360.0) % 360.0));
        add_text(&format!("pitch: {:.1}°", camera.rot.z.0));
        add_text(&format!(
            "blocks visible: {}/{}",
            self.blocks_visible, self.blocks,
        ));
    }
}