use crate::*; use winit::dpi::PhysicalSize; use winit::event::ElementState; use winit::keyboard::KeyCode; use std::path::PathBuf; pub enum Request { SetTitle(String), SetSize(Dimensions), SetSizeBounds(SizeBounds), SetResizable(bool), SetFullscreen(bool), SetVisible(bool), SetPixelScale(u32), SetCursor(Option), Redraw, CreateWindow(WindowBuilder), CloseWindow, } #[derive(Debug)] pub enum Event { Initialise, CloseRequest, Close, Resize(Dimensions), FocusChange(bool), CursorEnter, CursorExit, CursorMove(Position), ScrollLines { axis: Axis, distance: f32 }, ScrollPixels { axis: Axis, distance: f32 }, MouseButton { button: MouseButton, action: Action }, KeyboardInput { key: KeyCode, action: Action }, CharacterInput(char), ModifierChange(ModifiersState), FileDrop(PathBuf), } #[derive(Copy, Clone, Debug, PartialEq)] pub enum Action { Pressed, Released } impl Action { pub fn is_pressed(self) -> bool { self == Action::Pressed } } impl From for Action { fn from(value: ElementState) -> Self { match value { ElementState::Pressed => Action::Pressed, ElementState::Released => Action::Released, } } } #[derive(Copy, Clone, Debug, PartialEq)] pub enum Axis { Horizontal, Vertical, } #[derive(Copy, Clone, Debug, PartialEq)] pub enum MouseButton { Left, Middle, Right, } #[derive(Copy, Clone, Debug, PartialEq)] pub struct SizeBounds { pub min_width: Option, pub max_width: Option, pub min_height: Option, pub max_height: Option, } impl SizeBounds { pub fn as_min_max_size(&self, scale: u32) -> (PhysicalSize, PhysicalSize) { ( PhysicalSize { width: self.min_width.unwrap_or(0).saturating_mul(scale), height: self.min_height.unwrap_or(0).saturating_mul(scale), }, PhysicalSize { width: self.max_width.unwrap_or(u32::MAX).saturating_mul(scale), height: self.max_height.unwrap_or(u32::MAX).saturating_mul(scale), }, ) } } impl Default for SizeBounds { fn default() -> Self { Self { min_width: None, max_width: None, min_height: None, max_height: None, } } }