Skip to content

Commit

Permalink
Wasm druid-shell backend fills out MouseEvent for wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
teddemunnik committed May 8, 2020
1 parent f7dc7f3 commit d18891b
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions druid-shell/src/platform/web/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,26 @@ fn setup_scroll_callback(ws: &Rc<WindowState>) {
let height = state.canvas.height() as f64;
let width = state.canvas.width() as f64;

let modifiers = get_modifiers!(event);
let mut handler = state.handler.borrow_mut();

// The value 35.0 was manually picked to produce similar behavior to mac/linux.
match delta_mode {
web_sys::WheelEvent::DOM_DELTA_PIXEL => handler.wheel(Vec2::from((dx, dy)), modifiers),
web_sys::WheelEvent::DOM_DELTA_LINE => {
handler.wheel(Vec2::from((35.0 * dx, 35.0 * dy)), modifiers)
}
web_sys::WheelEvent::DOM_DELTA_PAGE => {
handler.wheel(Vec2::from((width * dx, height * dy)), modifiers)
let wheel_delta = match delta_mode {
web_sys::WheelEvent::DOM_DELTA_PIXEL => Vec2::new(dx, dy)
web_sys::WheelEvent::DOM_DELTA_LINE => Vec2::new(35.0 * dx, 35.0 * dy),
web_sys::WheelEvent::DOM_DELTA_PAGE => Vec2::new(width * dx, height * dy),
_ => {
log::warn!("Invalid deltaMode in WheelEvent: {}", delta_mode);
return;
}
_ => log::warn!("Invalid deltaMode in WheelEvent: {}", delta_mode),
}
};

let event = MouseEvent {
pos: Point::new(event.offset_x() as f64, event.offset_y() as f64),
buttons: mouse_buttons(event.buttons()),
mods: get_modifiers!(event),
count: 0,
button: MouseButton::None,
wheel_delta: wheel_delta
};
state.handler.borrow_mut().wheel(&event);
});
}

Expand Down

0 comments on commit d18891b

Please sign in to comment.