Skip to content

Commit 75cbecc

Browse files
committed
fix panning
1 parent dc56cd2 commit 75cbecc

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/window.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ impl App {
4545
pub(crate) fn window(&mut self) -> Option<&mut winit::window::Window> {
4646
self.window.as_mut()
4747
}
48+
#[cfg(feature = "wasm")]
49+
fn get_pos(
50+
&self,
51+
mut pos: winit::dpi::PhysicalPosition<f64>,
52+
) -> winit::dpi::PhysicalPosition<f64> {
53+
let window = web_sys::window().unwrap();
54+
let d = window.device_pixel_ratio();
55+
pos.x /= d;
56+
pos.y /= d;
57+
pos
58+
}
4859
}
4960
#[cfg(feature = "wasm")]
5061
use wasm_bindgen::JsCast;
@@ -220,6 +231,8 @@ impl winit::application::ApplicationHandler for App {
220231
}
221232
}
222233
winit::event::WindowEvent::CursorMoved { position, .. } => {
234+
#[cfg(feature = "wasm")]
235+
let position = self.get_pos(position);
223236
let bool = self.input_state.pointer.is_some()
224237
|| (self.input_state.pointer_right.is_some() && self.plot.is_drag())
225238
|| (!self.plot.is_3d
@@ -296,6 +309,8 @@ impl winit::application::ApplicationHandler for App {
296309
id,
297310
..
298311
}) => {
312+
#[cfg(feature = "wasm")]
313+
let location = self.get_pos(location);
299314
let Some(s) = self.window() else {
300315
return;
301316
};

0 commit comments

Comments
 (0)