baseview/event.rs
1use dpi::PhysicalPosition;
2use keyboard_types::{KeyboardEvent, Modifiers};
3use std::path::PathBuf;
4
5#[derive(Debug, Copy, Clone, Eq, PartialEq)]
6#[non_exhaustive]
7pub enum MouseButton {
8 Left,
9 Middle,
10 Right,
11 Back,
12 Forward,
13 Other(u8),
14}
15
16/// A scroll movement.
17#[derive(Debug, Clone, Copy, PartialEq)]
18pub enum ScrollDelta {
19 /// A line-based scroll movement
20 Lines {
21 /// The number of horizontal lines scrolled
22 x: f32,
23
24 /// The number of vertical lines scrolled
25 y: f32,
26 },
27 /// A pixel-based scroll movement
28 Pixels {
29 /// The number of horizontal pixels scrolled
30 x: f32,
31 /// The number of vertical pixels scrolled
32 y: f32,
33 },
34}
35
36#[derive(Debug, Clone, PartialEq)]
37#[non_exhaustive]
38pub enum MouseEvent {
39 /// The mouse cursor was moved
40 CursorMoved {
41 /// The logical coordinates of the mouse position
42 position: PhysicalPosition<f64>,
43 /// The modifiers that were held down just before the event.
44 modifiers: Modifiers,
45 },
46
47 /// A mouse button was pressed.
48 ButtonPressed {
49 /// The button that was pressed.
50 button: MouseButton,
51 /// The modifiers that were held down just before the event.
52 modifiers: Modifiers,
53 },
54
55 /// A mouse button was released.
56 ButtonReleased {
57 /// The button that was released.
58 button: MouseButton,
59 /// The modifiers that were held down just before the event.
60 modifiers: Modifiers,
61 },
62
63 /// The mouse wheel was scrolled.
64 WheelScrolled {
65 /// How much was scrolled, in factional lines.
66 delta: ScrollDelta,
67 /// The modifiers that were held down just before the event.
68 modifiers: Modifiers,
69 },
70
71 /// The mouse cursor entered the window.
72 ///
73 /// May not be available on all platforms.
74 CursorEntered,
75
76 /// The mouse cursor left the window.
77 ///
78 /// May not be available on all platforms.
79 CursorLeft,
80
81 DragEntered {
82 /// The logical coordinates of the mouse position
83 position: PhysicalPosition<f64>,
84 /// The modifiers that were held down just before the event.
85 modifiers: Modifiers,
86 /// Data being dragged
87 data: DropData,
88 },
89
90 DragMoved {
91 /// The logical coordinates of the mouse position
92 position: PhysicalPosition<f64>,
93 /// The modifiers that were held down just before the event.
94 modifiers: Modifiers,
95 /// Data being dragged
96 data: DropData,
97 },
98
99 DragLeft,
100
101 DragDropped {
102 /// The logical coordinates of the mouse position
103 position: PhysicalPosition<f64>,
104 /// The modifiers that were held down just before the event.
105 modifiers: Modifiers,
106 /// Data being dragged
107 data: DropData,
108 },
109}
110
111#[derive(Debug, Clone)]
112#[non_exhaustive]
113pub enum WindowEvent {
114 Focused,
115 Unfocused,
116 WillClose,
117}
118
119#[derive(Debug, Clone)]
120#[non_exhaustive]
121pub enum Event {
122 Mouse(MouseEvent),
123 Keyboard(KeyboardEvent),
124 Window(WindowEvent),
125}
126
127#[non_exhaustive]
128#[derive(Debug, Clone, Copy, PartialEq)]
129pub enum DropEffect {
130 Copy,
131 Move,
132 Link,
133 Scroll,
134}
135
136#[non_exhaustive]
137#[derive(Debug, Clone, PartialEq)]
138pub enum DropData {
139 None,
140 Files(Vec<PathBuf>),
141}
142
143/// Return value for [WindowHandler::on_event](`crate::WindowHandler::on_event()`),
144/// indicating whether the event was handled by your window or should be passed
145/// back to the platform.
146///
147/// For most event types, this value won't have any effect. This is the case
148/// when there is no clear meaning of passing back the event to the platform,
149/// or it isn't obviously useful. Currently, only [`Event::Keyboard`] variants
150/// are supported.
151#[derive(Debug, Clone, Copy, PartialEq)]
152#[non_exhaustive]
153pub enum EventStatus {
154 /// Event was handled by your window and will not be sent back to the
155 /// platform for further processing.
156 Captured,
157 /// Event was **not** handled by your window, so pass it back to the
158 /// platform. For parented windows, this usually means that the parent
159 /// window will receive the event. This is useful for cases such as using
160 /// DAW functionality for playing piano keys with the keyboard while a
161 /// plugin window is in focus.
162 Ignored,
163 /// We are prepared to handle the data in the drag and dropping will
164 /// result in [DropEffect]
165 AcceptDrop(DropEffect),
166}