Skip to content

Commit

Permalink
Fix web wheel event DPI handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
xStrom committed May 11, 2020
1 parent 9e6592c commit 6bd60a2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions druid-shell/src/platform/web/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,15 @@ fn setup_scroll_callback(ws: &Rc<WindowState>) {

let dx = event.delta_x();
let dy = event.delta_y();
let height = state.canvas.height() as f64;
let width = state.canvas.width() as f64;

// The value 35.0 was manually picked to produce similar behavior to mac/linux.
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),
web_sys::WheelEvent::DOM_DELTA_PAGE => {
let size_dp = state.scale.borrow().size_dp();
Vec2::new(size_dp.width * dx, size_dp.height * dy)
}
_ => {
log::warn!("Invalid deltaMode in WheelEvent: {}", delta_mode);
return;
Expand Down

0 comments on commit 6bd60a2

Please sign in to comment.