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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
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,
}
}
}
|