1
0
Fork 0
baseview/src/event.rs

115 lines
3.1 KiB
Rust
Raw Normal View History

use keyboard_types::{KeyboardEvent, Modifiers};
2020-10-15 13:17:03 -05:00
use crate::{Point, WindowInfo};
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
2020-09-11 10:21:05 -05:00
pub enum MouseButton {
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-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
position: Point,
/// 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.
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.
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.
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.
///
/// May not be available on all platforms.
2020-09-11 10:21:05 -05:00
CursorEntered,
/// The mouse cursor left the window.
///
/// May not be available on all platforms.
2020-09-11 10:21:05 -05:00
CursorLeft,
}
#[derive(Debug, Clone)]
2020-09-11 10:21:05 -05:00
pub enum WindowEvent {
Resized(WindowInfo),
Focused,
Unfocused,
WillClose,
}
#[derive(Debug, Clone)]
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
}
/// 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.
#[derive(Debug, Clone, Copy, PartialEq)]
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,
}