1use crate::{Keystroke, Modifiers};
4use kova_native_core::Point;
5
6#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
8pub enum MouseButton {
9 Left,
10 Right,
11 Middle,
12 Back,
13 Forward,
14 Other(u16),
15}
16
17#[derive(Clone, Copy, Debug, PartialEq)]
19pub enum ScrollDelta {
20 Lines(Point),
22 Pixels(Point),
24}
25
26impl ScrollDelta {
27 pub fn pixels(&self, line_height: f32) -> Point {
29 match *self {
30 ScrollDelta::Lines(p) => p * line_height,
31 ScrollDelta::Pixels(p) => p,
32 }
33 }
34}
35
36#[derive(Clone, Debug, PartialEq)]
37pub struct MouseDownEvent {
38 pub button: MouseButton,
39 pub position: Point,
40 pub modifiers: Modifiers,
41 pub click_count: u32,
43}
44
45#[derive(Clone, Debug, PartialEq)]
46pub struct MouseUpEvent {
47 pub button: MouseButton,
48 pub position: Point,
49 pub modifiers: Modifiers,
50 pub click_count: u32,
51}
52
53#[derive(Clone, Debug, PartialEq)]
54pub struct MouseMoveEvent {
55 pub position: Point,
56 pub pressed_button: Option<MouseButton>,
58 pub modifiers: Modifiers,
59}
60
61#[derive(Clone, Copy, Debug, PartialEq, Eq)]
63pub enum PenPhase {
64 Started,
65 Moved,
66 Ended,
67 Cancelled,
68}
69
70#[derive(Clone, Copy, Debug, PartialEq)]
72pub struct PenEvent {
73 pub pointer_id: u64,
75 pub phase: PenPhase,
76 pub position: Point,
77 pub pressure: f32,
79}
80
81#[derive(Clone, Debug, PartialEq)]
82pub struct ScrollWheelEvent {
83 pub position: Point,
84 pub delta: ScrollDelta,
85 pub modifiers: Modifiers,
86}
87
88#[derive(Clone, Debug, PartialEq)]
89pub struct KeyDownEvent {
90 pub keystroke: Keystroke,
91 pub is_repeat: bool,
93}
94
95#[derive(Clone, Debug, PartialEq)]
96pub struct KeyUpEvent {
97 pub keystroke: Keystroke,
98}
99
100#[derive(Clone, Debug, PartialEq)]
102pub enum ImeEvent {
103 Enabled,
104 Preedit {
106 text: String,
107 cursor: Option<(usize, usize)>,
108 },
109 Commit(String),
111 Disabled,
112}
113
114#[derive(Clone, Debug, PartialEq)]
116pub enum InputEvent {
117 MouseDown(MouseDownEvent),
118 MouseUp(MouseUpEvent),
119 MouseMove(MouseMoveEvent),
120 Pen(PenEvent),
122 MouseExit,
124 ScrollWheel(ScrollWheelEvent),
125 KeyDown(KeyDownEvent),
126 KeyUp(KeyUpEvent),
127 ModifiersChanged(Modifiers),
128 TextInput(String),
130 Ime(ImeEvent),
131}
132
133impl InputEvent {
134 pub fn position(&self) -> Option<Point> {
135 match self {
136 InputEvent::MouseDown(e) => Some(e.position),
137 InputEvent::MouseUp(e) => Some(e.position),
138 InputEvent::MouseMove(e) => Some(e.position),
139 InputEvent::Pen(e) => Some(e.position),
140 InputEvent::ScrollWheel(e) => Some(e.position),
141 _ => None,
142 }
143 }
144
145 pub fn is_keyboard(&self) -> bool {
146 matches!(
147 self,
148 InputEvent::KeyDown(_)
149 | InputEvent::KeyUp(_)
150 | InputEvent::TextInput(_)
151 | InputEvent::Ime(_)
152 )
153 }
154}
155
156#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
161pub enum DispatchPhase {
162 Capture,
163 Bubble,
164}
165
166#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
168pub enum CursorStyle {
169 #[default]
170 Arrow,
171 PointingHand,
172 IBeam,
173 Crosshair,
174 ClosedHand,
175 OpenHand,
176 NotAllowed,
177 ResizeLeftRight,
178 ResizeUpDown,
179 ResizeNwse,
180 ResizeNesw,
181 Move,
182 Wait,
183 Progress,
184}