2022-02-09 18:20:54 +01:00
|
|
|
use keyboard_types::{KeyboardEvent, Modifiers};
|
2020-10-15 13:17:03 -05:00
|
|
|
|
2021-11-10 17:57:54 +11:00
|
|
|
use crate::{Point, WindowInfo};
|
2020-11-13 20:41:17 +01:00
|
|
|
|
2020-09-02 16:22:49 -05:00
|
|
|
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
2020-09-11 10:21:05 -05:00
|
|
|
pub enum MouseButton {
|
2020-09-02 16:22:49 -05:00
|
|
|
Left,
|
|
|
|
Middle,
|
|
|
|
Right,
|
|
|
|
Back,
|
|
|
|
Forward,
|
|
|
|
Other(u8),
|
|
|
|
}
|
|
|
|
|
2020-09-11 10:21:05 -05:00
|
|
|
/// A scroll movement.
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
|
|
pub enum ScrollDelta {
|
|
|
|
/// A line-based scroll movement
|
|
|
|
Lines {
|
|
|
|
/// The number of horizontal lines scrolled
|
|
|
|
x: f32,
|
|
|
|
|
|
|
|
/// The number of vertical lines scrolled
|
|
|
|
y: f32,
|
|
|
|
},
|
|
|
|
/// A pixel-based scroll movement
|
|
|
|
Pixels {
|
|
|
|
/// The number of horizontal pixels scrolled
|
|
|
|
x: f32,
|
|
|
|
/// The number of vertical pixels scrolled
|
|
|
|
y: f32,
|
|
|
|
},
|
2020-09-02 16:22:49 -05:00
|
|
|
}
|
|
|
|
|
2020-09-11 10:21:05 -05:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
|
|
pub enum MouseEvent {
|
|
|
|
/// The mouse cursor was moved
|
|
|
|
CursorMoved {
|
2020-10-17 14:01:03 -05:00
|
|
|
/// The logical coordinates of the mouse position
|
2020-10-17 17:27:06 -05:00
|
|
|
position: Point,
|
2022-02-09 18:20:54 +01:00
|
|
|
/// The modifiers that were held down just before the event.
|
|
|
|
modifiers: Modifiers,
|
2020-09-11 10:21:05 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/// A mouse button was pressed.
|
2022-02-09 18:20:54 +01:00
|
|
|
ButtonPressed {
|
|
|
|
/// The button that was pressed.
|
|
|
|
button: MouseButton,
|
|
|
|
/// The modifiers that were held down just before the event.
|
|
|
|
modifiers: Modifiers,
|
|
|
|
},
|
2020-09-11 10:21:05 -05:00
|
|
|
|
|
|
|
/// A mouse button was released.
|
2022-02-09 18:20:54 +01:00
|
|
|
ButtonReleased {
|
|
|
|
/// The button that was released.
|
|
|
|
button: MouseButton,
|
|
|
|
/// The modifiers that were held down just before the event.
|
|
|
|
modifiers: Modifiers,
|
|
|
|
},
|
2020-09-11 10:21:05 -05:00
|
|
|
|
|
|
|
/// The mouse wheel was scrolled.
|
2022-02-09 18:20:54 +01:00
|
|
|
WheelScrolled {
|
|
|
|
/// How much was scrolled, in factional lines.
|
|
|
|
delta: ScrollDelta,
|
|
|
|
/// The modifiers that were held down just before the event.
|
|
|
|
modifiers: Modifiers,
|
|
|
|
},
|
2020-09-11 10:21:05 -05:00
|
|
|
|
|
|
|
/// The mouse cursor entered the window.
|
2022-02-09 18:20:54 +01:00
|
|
|
///
|
|
|
|
/// May not be available on all platforms.
|
2020-09-11 10:21:05 -05:00
|
|
|
CursorEntered,
|
|
|
|
|
|
|
|
/// The mouse cursor left the window.
|
2022-02-09 18:20:54 +01:00
|
|
|
///
|
|
|
|
/// May not be available on all platforms.
|
2020-09-11 10:21:05 -05:00
|
|
|
CursorLeft,
|
|
|
|
}
|
|
|
|
|
2021-02-09 21:47:31 +01:00
|
|
|
#[derive(Debug, Clone)]
|
2020-09-11 10:21:05 -05:00
|
|
|
pub enum WindowEvent {
|
|
|
|
Resized(WindowInfo),
|
|
|
|
Focused,
|
|
|
|
Unfocused,
|
|
|
|
WillClose,
|
|
|
|
}
|
|
|
|
|
2021-02-09 21:47:31 +01:00
|
|
|
#[derive(Debug, Clone)]
|
2020-09-03 11:38:22 -05:00
|
|
|
pub enum Event {
|
2020-09-11 10:21:05 -05:00
|
|
|
Mouse(MouseEvent),
|
|
|
|
Keyboard(KeyboardEvent),
|
2020-09-11 12:38:06 -05:00
|
|
|
Window(WindowEvent),
|
2020-09-02 16:23:03 -05:00
|
|
|
}
|
2021-02-09 21:47:31 +01:00
|
|
|
|
|
|
|
/// Return value for [WindowHandler::on_event](`crate::WindowHandler::on_event()`),
|
|
|
|
/// indicating whether the event was handled by your window or should be passed
|
|
|
|
/// back to the platform.
|
|
|
|
///
|
|
|
|
/// For most event types, this value won't have any effect. This is the case
|
|
|
|
/// when there is no clear meaning of passing back the event to the platform,
|
|
|
|
/// or it isn't obviously useful. Currently, only [`Event::Keyboard`] variants
|
|
|
|
/// are supported.
|
2021-02-10 17:01:49 +01:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
2021-02-09 21:47:31 +01:00
|
|
|
pub enum EventStatus {
|
|
|
|
/// Event was handled by your window and will not be sent back to the
|
|
|
|
/// platform for further processing.
|
|
|
|
Captured,
|
|
|
|
/// Event was **not** handled by your window, so pass it back to the
|
|
|
|
/// platform. For parented windows, this usually means that the parent
|
|
|
|
/// window will receive the event. This is useful for cases such as using
|
|
|
|
/// DAW functionality for playing piano keys with the keyboard while a
|
|
|
|
/// plugin window is in focus.
|
|
|
|
Ignored,
|
|
|
|
}
|