maycoon_core/app/
info.rs

1use nalgebra::Vector2;
2use winit::event::{DeviceId, ElementState, KeyEvent, MouseButton, MouseScrollDelta};
3
4use crate::app::diagnostics::Diagnostics;
5use crate::app::font_ctx::FontContext;
6
7/// The application information container.
8pub struct AppInfo {
9    /// The position of the cursor. If [None], the cursor left the window.
10    pub cursor_pos: Option<Vector2<f32>>,
11    /// The fired key events.
12    pub keys: Vec<(DeviceId, KeyEvent)>,
13    /// The fired mouse button events.
14    pub buttons: Vec<(DeviceId, MouseButton, ElementState)>,
15    /// The mouse scroll delta, if a [winit::event::WindowEvent::MouseWheel] event was fired.
16    pub mouse_scroll_delta: Option<MouseScrollDelta>,
17    /// App Diagnostics.
18    pub diagnostics: Diagnostics,
19    /// The current font context.
20    pub font_context: FontContext,
21    /// The size of the window.
22    pub size: Vector2<f64>,
23}
24
25impl AppInfo {
26    /// Reset the application information for a new frame.
27    #[inline(always)]
28    #[tracing::instrument(level = "trace", skip_all)]
29    pub fn reset(&mut self) {
30        self.buttons.clear();
31        self.keys.clear();
32        self.mouse_scroll_delta = None;
33    }
34}
35
36impl Default for AppInfo {
37    #[inline(always)]
38    fn default() -> Self {
39        Self {
40            cursor_pos: None,
41            keys: Vec::with_capacity(4),
42            buttons: Vec::with_capacity(2),
43            mouse_scroll_delta: None,
44            diagnostics: Diagnostics::default(),
45            font_context: FontContext::default(),
46            size: Vector2::new(0.0, 0.0),
47        }
48    }
49}