Commit d06563ce authored by Florian Blasius's avatar Florian Blasius 🤘

add web scroll event

parent 3cce14e4
Pipeline #9063 passed with stage
in 3 minutes and 3 seconds
......@@ -29,7 +29,26 @@ redox_syscall = { version = "0.2.1" }
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2.69"
# js-sys = "0.3"
web-sys = { version = "0.3", features = ["Node", "Element", "console", "CanvasRenderingContext2d", "Document", "Element", "ImageData", "HtmlCanvasElement", "HtmlElement", "Window", "CssStyleDeclaration", "MouseEvent", "KeyboardEvent", "DomRect"] }
[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys]
version = "0.3"
features = [
"Node",
"Element",
"console",
"CanvasRenderingContext2d",
"Document",
"Element",
"ImageData",
"HtmlCanvasElement",
"HtmlElement",
"Window",
"CssStyleDeclaration",
"MouseEvent",
"KeyboardEvent",
"WheelEvent",
"DomRect"
]
[features]
default = ["bundled"]
......
......@@ -273,6 +273,26 @@ impl Window {
closure.forget();
}
// wheel (scroll)
{
let events = events.clone();
let closure = Closure::wrap(Box::new(move |e: web_sys::WheelEvent| {
events.borrow_mut().push(
ScrollEvent {
x: e.delta_x() as i32,
y: e.delta_y() as i32,
}
.to_event(),
)
}) as Box<dyn FnMut(_)>);
document()
.unwrap()
.add_event_listener_with_callback("wheel", closure.as_ref().unchecked_ref())
.unwrap();
closure.forget();
}
if let Ok(context) = context_2d(&canvas) {
return Some(Window {
x,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment