mod render; mod window; mod window_controller; mod window_manager; pub use render::*; pub use window::*; pub use window_controller::*; pub use window_manager::*; pub use buffer::{Buffer, Colour}; pub use winit::{ event::{ModifiersState, ElementState}, event::VirtualKeyCode as KeyCode, window::CursorIcon, }; pub use std::num::NonZeroU32; pub type Point = geometry::Point; pub type Dimensions = geometry::Dimensions; pub type Rect = geometry::Rect; // ----------------------------------------------------------------------------- #[derive(Copy, Clone)] pub struct KeyboardInput { pub action: Action, pub key: KeyCode, } impl TryFrom for KeyboardInput { type Error = (); fn try_from(input: winit::event::KeyboardInput) -> Result { if let Some(key) = input.virtual_keycode { Ok( Self { action: input.state.into(), key } ) } else { Err(()) } } } // ----------------------------------------------------------------------------- #[derive(Clone, Copy, PartialEq, Debug)] pub enum Action { Pressed, Released } impl Action { pub fn is_pressed(&self) -> bool { *self == Self::Pressed } pub fn is_released(&self) -> bool { *self == Self::Released } } impl From for Action { fn from(value: ElementState) -> Self { match value { ElementState::Pressed => Action::Pressed, ElementState::Released => Action::Released, } } }