Checkpoint

This commit is contained in:
Nathan Sobo
2023-10-09 21:30:14 -06:00
parent 9fe5836240
commit dfdb691f73
2 changed files with 65 additions and 74 deletions
+61 -70
View File
@@ -34,61 +34,20 @@ pub enum TouchPhase {
Ended, Ended,
} }
#[derive(Clone, Copy, Debug)] #[derive(Clone, Debug, Default)]
pub enum ScrollDelta { pub struct MouseDownEvent {
Pixels(Point<Pixels>), pub button: MouseButton,
Lines(Point<f32>), pub position: Point<Pixels>,
} pub modifiers: Modifiers,
pub click_count: usize,
impl Default for ScrollDelta {
fn default() -> Self {
Self::Lines(Default::default())
}
}
impl ScrollDelta {
pub fn precise(&self) -> bool {
match self {
ScrollDelta::Pixels(_) => true,
ScrollDelta::Lines(_) => false,
}
}
pub fn pixel_delta(&self, line_height: Pixels) -> Point<Pixels> {
match self {
ScrollDelta::Pixels(delta) => *delta,
ScrollDelta::Lines(delta) => point(line_height * delta.x, line_height * delta.y),
}
}
} }
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
pub struct ScrollWheelEvent { pub struct MouseUpEvent {
pub button: MouseButton,
pub position: Point<Pixels>, pub position: Point<Pixels>,
pub delta: ScrollDelta,
pub modifiers: Modifiers, pub modifiers: Modifiers,
/// If the platform supports returning the phase of a scroll wheel event, it will be stored here pub click_count: usize,
pub phase: Option<TouchPhase>,
}
impl Deref for ScrollWheelEvent {
type Target = Modifiers;
fn deref(&self) -> &Self::Target {
&self.modifiers
}
}
#[derive(Hash, PartialEq, Eq, Copy, Clone, Debug)]
pub enum NavigationDirection {
Back,
Forward,
}
impl Default for NavigationDirection {
fn default() -> Self {
Self::Back
}
} }
#[derive(Hash, PartialEq, Eq, Copy, Clone, Debug)] #[derive(Hash, PartialEq, Eq, Copy, Clone, Debug)]
@@ -117,28 +76,16 @@ impl Default for MouseButton {
} }
} }
#[derive(Clone, Debug, Default)] #[derive(Hash, PartialEq, Eq, Copy, Clone, Debug)]
pub struct MouseDownEvent { pub enum NavigationDirection {
pub button: MouseButton, Back,
pub position: Point<Pixels>, Forward,
pub modifiers: Modifiers,
pub click_count: usize,
} }
#[derive(Clone, Debug, Default)] impl Default for NavigationDirection {
pub struct MouseUpEvent { fn default() -> Self {
pub button: MouseButton, Self::Back
pub position: Point<Pixels>, }
pub modifiers: Modifiers,
pub click_count: usize,
}
#[derive(Clone, Debug, Default)]
pub struct MouseUp {
pub button: MouseButton,
pub position: Point<Pixels>,
pub modifiers: Modifiers,
pub click_count: usize,
} }
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
@@ -148,6 +95,50 @@ pub struct MouseMovedEvent {
pub modifiers: Modifiers, pub modifiers: Modifiers,
} }
#[derive(Clone, Debug)]
pub struct ScrollWheelEvent {
pub position: Point<Pixels>,
pub delta: ScrollDelta,
pub modifiers: Modifiers,
pub touch_phase: TouchPhase,
}
impl Deref for ScrollWheelEvent {
type Target = Modifiers;
fn deref(&self) -> &Self::Target {
&self.modifiers
}
}
#[derive(Clone, Copy, Debug)]
pub enum ScrollDelta {
Pixels(Point<Pixels>),
Lines(Point<f32>),
}
impl Default for ScrollDelta {
fn default() -> Self {
Self::Lines(Default::default())
}
}
impl ScrollDelta {
pub fn precise(&self) -> bool {
match self {
ScrollDelta::Pixels(_) => true,
ScrollDelta::Lines(_) => false,
}
}
pub fn pixel_delta(&self, line_height: Pixels) -> Point<Pixels> {
match self {
ScrollDelta::Pixels(delta) => *delta,
ScrollDelta::Lines(delta) => point(line_height * delta.x, line_height * delta.y),
}
}
}
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
pub struct MouseExitedEvent { pub struct MouseExitedEvent {
pub position: Point<Pixels>, pub position: Point<Pixels>,
+4 -4
View File
@@ -161,10 +161,10 @@ impl Event {
NSEventType::NSScrollWheel => window_height.map(|window_height| { NSEventType::NSScrollWheel => window_height.map(|window_height| {
let phase = match native_event.phase() { let phase = match native_event.phase() {
NSEventPhase::NSEventPhaseMayBegin | NSEventPhase::NSEventPhaseBegan => { NSEventPhase::NSEventPhaseMayBegin | NSEventPhase::NSEventPhaseBegan => {
Some(TouchPhase::Started) TouchPhase::Started
} }
NSEventPhase::NSEventPhaseEnded => Some(TouchPhase::Ended), NSEventPhase::NSEventPhaseEnded => TouchPhase::Ended,
_ => Some(TouchPhase::Moved), _ => TouchPhase::Moved,
}; };
let raw_data = point( let raw_data = point(
@@ -184,7 +184,7 @@ impl Event {
window_height - px(native_event.locationInWindow().y as f32), window_height - px(native_event.locationInWindow().y as f32),
), ),
delta, delta,
phase, touch_phase: phase,
modifiers: read_modifiers(native_event), modifiers: read_modifiers(native_event),
}) })
}), }),