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<CursorIcon>),
SetIcon(Option<Icon>),
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<ElementState> 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,
Back,
Forward,
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct SizeBounds {
pub min_width: Option<u32>,
pub max_width: Option<u32>,
pub min_height: Option<u32>,
pub max_height: Option<u32>,
}
impl SizeBounds {
pub fn as_min_max_size(&self, scale: u32) -> (PhysicalSize<u32>, PhysicalSize<u32>) {
(
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,
}
}
}