pub use device::*;
pub use window::*;
pub use winit::event::AxisId;
pub use winit::event::ButtonId;
pub use winit::event::DeviceId;
pub use winit::event::Force;
pub use winit::event::ModifiersState;
pub use winit::event::MouseScrollDelta;
pub use winit::event::ScanCode;
pub use winit::event::StartCause;
pub use winit::event::Touch;
pub use winit::event::TouchPhase;
pub use winit::event::VirtualKeyCode;
macro_rules! impl_from_variant {
($for:ident::$variant:ident($from:ty)) => {
impl From<$from> for $for {
fn from(other: $from) -> Self {
Self::$variant(other)
}
}
};
}
mod device;
mod window;
#[derive(Debug, Default, Clone)]
pub struct EventHandlerControlFlow {
pub remove_handler: bool,
pub stop_propagation: bool,
}
#[derive(Debug, Clone)]
pub enum Event {
NewEvents,
WindowEvent(WindowEvent),
DeviceEvent(DeviceEvent),
Suspended,
Resumed,
MainEventsCleared,
RedrawEventsCleared,
AllWindowsClosed,
}
impl_from_variant!(Event::WindowEvent(WindowEvent));
impl_from_variant!(Event::DeviceEvent(DeviceEvent));
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct KeyboardInput {
pub scan_code: ScanCode,
pub key_code: Option<VirtualKeyCode>,
pub state: ElementState,
pub modifiers: ModifiersState,
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Theme {
Light,
Dark,
}
impl Theme {
pub fn is_light(self) -> bool {
self == Self::Light
}
pub fn is_dark(self) -> bool {
self == Self::Dark
}
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum ElementState {
Pressed,
Released,
}
impl ElementState {
pub fn is_pressed(self) -> bool {
self == Self::Pressed
}
pub fn is_released(self) -> bool {
self == Self::Released
}
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum MouseButton {
Left,
Right,
Middle,
Other(u16),
}
impl MouseButton {
pub fn is_left(self) -> bool {
self == Self::Left
}
pub fn is_right(self) -> bool {
self == Self::Right
}
pub fn is_middle(self) -> bool {
self == Self::Middle
}
pub fn is_other(self, other: u16) -> bool {
self == Self::Other(other)
}
}
#[derive(Debug, Clone, Default)]
pub struct MouseButtonState {
buttons: std::collections::BTreeSet<MouseButton>,
}
impl MouseButtonState {
pub fn is_pressed(&self, button: MouseButton) -> bool {
self.buttons.get(&button).is_some()
}
pub fn iter_pressed(&self) -> impl Iterator<Item = MouseButton> + '_ {
self.buttons.iter().copied()
}
pub fn set_pressed(&mut self, button: MouseButton, pressed: bool) {
if pressed {
self.buttons.insert(button);
} else {
self.buttons.remove(&button);
}
}
}