use super::AxisId;
use super::DeviceId;
use super::ElementState;
use super::KeyboardInput;
use super::ModifiersState;
use super::MouseButton;
use super::MouseButtonState;
use super::MouseScrollDelta;
use super::Theme;
use super::Touch;
use super::TouchPhase;
use crate::WindowId;
use std::path::PathBuf;
#[derive(Debug, Clone)]
pub enum WindowEvent {
RedrawRequested(WindowRedrawRequestedEvent),
Resized(WindowResizedEvent),
Moved(WindowMovedEvent),
CloseRequested(WindowCloseRequestedEvent),
Destroyed(WindowDestroyedEvent),
DroppedFile(WindowDroppedFileEvent),
HoveredFile(WindowHoveredFileEvent),
HoveredFileCancelled(WindowHoveredFileCancelledEvent),
FocusGained(WindowFocusGainedEvent),
FocusLost(WindowFocusLostEvent),
KeyboardInput(WindowKeyboardInputEvent),
TextInput(WindowTextInputEvent),
MouseEnter(WindowMouseEnterEvent),
MouseLeave(WindowMouseLeaveEvent),
MouseMove(WindowMouseMoveEvent),
MouseButton(WindowMouseButtonEvent),
MouseWheel(WindowMouseWheelEvent),
AxisMotion(WindowAxisMotionEvent),
TouchpadPressure(WindowTouchpadPressureEvent),
TouchpadMagnify(WindowTouchpadMagnifyEvent),
TouchpadRotate(WindowTouchpadRotateEvent),
Touch(WindowTouchEvent),
ScaleFactorChanged(WindowScaleFactorChangedEvent),
ThemeChanged(WindowThemeChangedEvent),
}
impl WindowEvent {
pub fn window_id(&self) -> WindowId {
match self {
Self::RedrawRequested(x) => x.window_id,
Self::Resized(x) => x.window_id,
Self::Moved(x) => x.window_id,
Self::CloseRequested(x) => x.window_id,
Self::Destroyed(x) => x.window_id,
Self::DroppedFile(x) => x.window_id,
Self::HoveredFile(x) => x.window_id,
Self::HoveredFileCancelled(x) => x.window_id,
Self::FocusGained(x) => x.window_id,
Self::FocusLost(x) => x.window_id,
Self::KeyboardInput(x) => x.window_id,
Self::TextInput(x) => x.window_id,
Self::MouseEnter(x) => x.window_id,
Self::MouseLeave(x) => x.window_id,
Self::MouseMove(x) => x.window_id,
Self::MouseButton(x) => x.window_id,
Self::MouseWheel(x) => x.window_id,
Self::AxisMotion(x) => x.window_id,
Self::TouchpadPressure(x) => x.window_id,
Self::TouchpadMagnify(x) => x.window_id,
Self::TouchpadRotate(x) => x.window_id,
Self::Touch(x) => x.window_id,
Self::ScaleFactorChanged(x) => x.window_id,
Self::ThemeChanged(x) => x.window_id,
}
}
}
#[derive(Debug, Clone)]
pub struct WindowRedrawRequestedEvent {
pub window_id: WindowId,
}
#[derive(Debug, Clone)]
pub struct WindowResizedEvent {
pub window_id: WindowId,
pub size: glam::UVec2,
}
#[derive(Debug, Clone)]
pub struct WindowMovedEvent {
pub window_id: WindowId,
pub position: glam::IVec2,
}
#[derive(Debug, Clone)]
pub struct WindowCloseRequestedEvent {
pub window_id: WindowId,
}
#[derive(Debug, Clone)]
pub struct WindowDestroyedEvent {
pub window_id: WindowId,
}
#[derive(Debug, Clone)]
pub struct WindowDroppedFileEvent {
pub window_id: WindowId,
pub file: PathBuf,
}
#[derive(Debug, Clone)]
pub struct WindowHoveredFileEvent {
pub window_id: WindowId,
pub file: PathBuf,
}
#[derive(Debug, Clone)]
pub struct WindowHoveredFileCancelledEvent {
pub window_id: WindowId,
}
#[derive(Debug, Clone)]
pub struct WindowFocusGainedEvent {
pub window_id: WindowId,
}
#[derive(Debug, Clone)]
pub struct WindowFocusLostEvent {
pub window_id: WindowId,
}
#[derive(Debug, Clone)]
pub struct WindowKeyboardInputEvent {
pub window_id: WindowId,
pub device_id: DeviceId,
pub input: KeyboardInput,
pub is_synthetic: bool,
}
#[derive(Debug, Clone)]
pub struct WindowTextInputEvent {
pub window_id: WindowId,
pub character: char,
}
#[derive(Debug, Clone)]
pub struct WindowMouseEnterEvent {
pub window_id: WindowId,
pub device_id: DeviceId,
pub buttons: MouseButtonState,
}
#[derive(Debug, Clone)]
pub struct WindowMouseLeaveEvent {
pub window_id: WindowId,
pub device_id: DeviceId,
pub buttons: MouseButtonState,
}
#[derive(Debug, Clone)]
pub struct WindowMouseMoveEvent {
pub window_id: WindowId,
pub device_id: DeviceId,
pub position: glam::Vec2,
pub prev_position: glam::Vec2,
pub buttons: MouseButtonState,
pub modifiers: ModifiersState,
}
#[derive(Debug, Clone)]
pub struct WindowMouseButtonEvent {
pub window_id: WindowId,
pub device_id: DeviceId,
pub button: MouseButton,
pub state: ElementState,
pub position: glam::Vec2,
pub prev_position: glam::Vec2,
pub buttons: MouseButtonState,
pub modifiers: ModifiersState,
}
#[derive(Debug, Clone)]
pub struct WindowMouseWheelEvent {
pub window_id: WindowId,
pub device_id: DeviceId,
pub delta: MouseScrollDelta,
pub phase: TouchPhase,
pub position: Option<glam::Vec2>,
pub buttons: MouseButtonState,
pub modifiers: ModifiersState,
}
#[derive(Debug, Clone)]
pub struct WindowAxisMotionEvent {
pub window_id: WindowId,
pub device_id: DeviceId,
pub axis: AxisId,
pub value: f64,
}
#[derive(Debug, Clone)]
pub struct WindowTouchpadPressureEvent {
pub window_id: WindowId,
pub device_id: DeviceId,
pub pressure: f32,
pub stage: i64,
}
#[derive(Debug, Clone)]
pub struct WindowTouchpadMagnifyEvent {
pub window_id: WindowId,
pub device_id: DeviceId,
pub scale: f64,
pub phase: TouchPhase,
}
#[derive(Debug, Clone)]
pub struct WindowTouchpadRotateEvent {
pub window_id: WindowId,
pub device_id: DeviceId,
pub angle_radians: f64,
pub phase: TouchPhase,
}
#[derive(Debug, Clone)]
pub struct WindowTouchEvent {
pub window_id: WindowId,
pub touch: Touch,
}
#[derive(Debug, Clone)]
pub struct WindowScaleFactorChangedEvent {
pub window_id: WindowId,
pub scale_factor: f64,
}
#[derive(Debug, Clone)]
pub struct WindowThemeChangedEvent {
pub window_id: WindowId,
pub theme: Theme,
}
impl_from_variant!(WindowEvent::RedrawRequested(WindowRedrawRequestedEvent));
impl_from_variant!(WindowEvent::Resized(WindowResizedEvent));
impl_from_variant!(WindowEvent::Moved(WindowMovedEvent));
impl_from_variant!(WindowEvent::CloseRequested(WindowCloseRequestedEvent));
impl_from_variant!(WindowEvent::Destroyed(WindowDestroyedEvent));
impl_from_variant!(WindowEvent::DroppedFile(WindowDroppedFileEvent));
impl_from_variant!(WindowEvent::HoveredFile(WindowHoveredFileEvent));
impl_from_variant!(WindowEvent::HoveredFileCancelled(WindowHoveredFileCancelledEvent));
impl_from_variant!(WindowEvent::FocusGained(WindowFocusGainedEvent));
impl_from_variant!(WindowEvent::FocusLost(WindowFocusLostEvent));
impl_from_variant!(WindowEvent::KeyboardInput(WindowKeyboardInputEvent));
impl_from_variant!(WindowEvent::TextInput(WindowTextInputEvent));
impl_from_variant!(WindowEvent::MouseEnter(WindowMouseEnterEvent));
impl_from_variant!(WindowEvent::MouseLeave(WindowMouseLeaveEvent));
impl_from_variant!(WindowEvent::MouseMove(WindowMouseMoveEvent));
impl_from_variant!(WindowEvent::MouseButton(WindowMouseButtonEvent));
impl_from_variant!(WindowEvent::MouseWheel(WindowMouseWheelEvent));
impl_from_variant!(WindowEvent::AxisMotion(WindowAxisMotionEvent));
impl_from_variant!(WindowEvent::TouchpadPressure(WindowTouchpadPressureEvent));
impl_from_variant!(WindowEvent::TouchpadMagnify(WindowTouchpadMagnifyEvent));
impl_from_variant!(WindowEvent::TouchpadRotate(WindowTouchpadRotateEvent));
impl_from_variant!(WindowEvent::Touch(WindowTouchEvent));
impl_from_variant!(WindowEvent::ScaleFactorChanged(WindowScaleFactorChangedEvent));
impl_from_variant!(WindowEvent::ThemeChanged(WindowThemeChangedEvent));