diff --git a/src/macos/view.rs b/src/macos/view.rs index c39ba15..76014b3 100644 --- a/src/macos/view.rs +++ b/src/macos/view.rs @@ -15,7 +15,7 @@ use uuid::Uuid; use crate::MouseEvent::{ButtonPressed, ButtonReleased}; use crate::{ - Event, EventStatus, MouseButton, MouseEvent, Point, Size, WindowEvent, WindowInfo, + Event, EventStatus, MouseButton, MouseEvent, Point, ScrollDelta, Size, WindowEvent, WindowInfo, WindowOpenOptions, }; @@ -147,6 +147,8 @@ unsafe fn create_view_class() -> &'static Class { class.add_method(sel!(rightMouseDragged:), mouse_moved as extern "C" fn(&Object, Sel, id)); class.add_method(sel!(otherMouseDragged:), mouse_moved as extern "C" fn(&Object, Sel, id)); + class.add_method(sel!(scrollWheel:), scroll_wheel as extern "C" fn(&Object, Sel, id)); + class.add_method( sel!(viewDidChangeBackingProperties:), view_did_change_backing_properties as extern "C" fn(&Object, Sel, id), @@ -343,3 +345,20 @@ extern "C" fn mouse_moved(this: &Object, _sel: Sel, event: id) { modifiers: make_modifiers(modifiers), })); } + +extern "C" fn scroll_wheel(this: &Object, _: Sel, event: id) { + let state: &mut WindowState = unsafe { WindowState::from_field(this) }; + + let delta = unsafe { + let x = NSEvent::scrollingDeltaX(event) as f32; + let y = NSEvent::scrollingDeltaY(event) as f32; + + if NSEvent::hasPreciseScrollingDeltas(event) != NO { + ScrollDelta::Pixels { x, y } + } else { + ScrollDelta::Lines { x, y } + } + }; + + state.trigger_event(Event::Mouse(MouseEvent::WheelScrolled(delta))); +}