use crate::{_impl_init, EventButtons, KeyMods, Position2};
#[doc = crate::_tags!(event interaction)]
#[doc = crate::_doc_meta!{
location("ui/event"),
test_size_of(EventWheel = 20|160; niche Option),
}]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct EventWheel {
pub delta_x: i32,
pub delta_y: i32,
pub unit: EventWheelUnit,
pub x: i32,
pub y: i32,
pub buttons: EventButtons,
pub mods: KeyMods,
}
_impl_init! {
Self::new(0, 0, EventWheelUnit::INIT, 0, 0, EventButtons::INIT, KeyMods::INIT) => EventWheel
}
#[rustfmt::skip]
impl EventWheel {
pub const fn new(delta_x: i32, delta_y: i32, unit: EventWheelUnit,
x: i32, y: i32, buttons: EventButtons, mods: KeyMods) -> Self {
Self { delta_x, delta_y, unit, x, y, buttons, mods }
}
#[must_use]
pub const fn delta(&self) -> (i32, i32) { (self.delta_x, self.delta_y) }
pub const fn pos(&self) -> Position2<i32> { Position2::new([self.x, self.y]) }
pub const fn xy(&self) -> (i32, i32) { (self.x, self.y) }
#[must_use]
pub const fn has_x(&self) -> bool { self.delta_x != 0 }
#[must_use]
pub const fn has_y(&self) -> bool { self.delta_y != 0 }
#[must_use]
pub const fn is_zero(&self) -> bool { self.delta_x == 0 && self.delta_y == 0 }
#[must_use]
pub const fn is_up(&self) -> bool { self.delta_y < 0 }
#[must_use]
pub const fn is_down(&self) -> bool { self.delta_y > 0 }
#[must_use]
pub const fn is_right(&self) -> bool { self.delta_x > 0 }
#[must_use]
pub const fn is_left(&self) -> bool { self.delta_x < 0 }
#[must_use]
pub const fn is_step(&self) -> bool { matches!(self.unit, EventWheelUnit::Step) }
#[must_use]
pub const fn is_pixel(&self) -> bool { matches!(self.unit, EventWheelUnit::Pixel) }
#[must_use]
pub const fn is_line(&self) -> bool { matches!(self.unit, EventWheelUnit::Line) }
#[must_use]
pub const fn is_page(&self) -> bool { matches!(self.unit, EventWheelUnit::Page) }
}
#[doc = crate::_tags!(event interaction)]
#[doc = crate::_doc_meta!{ location("ui/event") }]
#[allow(missing_docs)]
#[repr(u8)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum EventWheelUnit {
#[default]
Step,
Pixel,
Line,
Page,
}
_impl_init! { Self::Step => EventWheelUnit }
impl EventWheelUnit {
pub const fn from_web(code: u8) -> Self {
match code {
0 => Self::Pixel,
1 => Self::Line,
2 => Self::Page,
_ => Self::Step,
}
}
pub const fn to_web(self) -> u8 {
match self {
Self::Pixel => 0,
Self::Line => 1,
Self::Page => 2,
Self::Step => 1,
}
}
}