mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-11-24 06:33:33 +03:00
Switch Closure::new
to wrap
in paint example
Show off stable usage!
This commit is contained in:
parent
4a5e13b08b
commit
991e61931e
@ -8,7 +8,7 @@ crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
js-sys = { path = "../../crates/js-sys" }
|
||||
wasm-bindgen = { path = "../..", features = ["nightly"] }
|
||||
wasm-bindgen = { path = "../.." }
|
||||
|
||||
[dependencies.web-sys]
|
||||
path = "../../crates/web-sys"
|
||||
|
@ -36,11 +36,11 @@ pub fn main() {
|
||||
{
|
||||
let context = context.clone();
|
||||
let pressed = pressed.clone();
|
||||
let closure: Closure<FnMut(_)> = Closure::new(move |event: web_sys::MouseEvent| {
|
||||
let closure = Closure::wrap(Box::new(move |event: web_sys::MouseEvent| {
|
||||
context.begin_path();
|
||||
context.move_to(event.offset_x() as f64, event.offset_y() as f64);
|
||||
pressed.set(true);
|
||||
});
|
||||
}) as Box<FnMut(_)>);
|
||||
(canvas.as_ref() as &web_sys::EventTarget)
|
||||
.add_event_listener_with_callback("mousedown", closure.as_ref().unchecked_ref())
|
||||
.unwrap();
|
||||
@ -49,14 +49,14 @@ pub fn main() {
|
||||
{
|
||||
let context = context.clone();
|
||||
let pressed = pressed.clone();
|
||||
let closure: Closure<FnMut(_)> = Closure::new(move |event: web_sys::MouseEvent| {
|
||||
let closure = Closure::wrap(Box::new(move |event: web_sys::MouseEvent| {
|
||||
if pressed.get() {
|
||||
context.line_to(event.offset_x() as f64, event.offset_y() as f64);
|
||||
context.stroke();
|
||||
context.begin_path();
|
||||
context.move_to(event.offset_x() as f64, event.offset_y() as f64);
|
||||
}
|
||||
});
|
||||
}) as Box<FnMut(_)>);
|
||||
(canvas.as_ref() as &web_sys::EventTarget)
|
||||
.add_event_listener_with_callback("mousemove", closure.as_ref().unchecked_ref())
|
||||
.unwrap();
|
||||
@ -65,11 +65,11 @@ pub fn main() {
|
||||
{
|
||||
let context = context.clone();
|
||||
let pressed = pressed.clone();
|
||||
let closure: Closure<FnMut(_)> = Closure::new(move |event: web_sys::MouseEvent| {
|
||||
let closure = Closure::wrap(Box::new(move |event: web_sys::MouseEvent| {
|
||||
pressed.set(false);
|
||||
context.line_to(event.offset_x() as f64, event.offset_y() as f64);
|
||||
context.stroke();
|
||||
});
|
||||
}) as Box<FnMut(_)>);
|
||||
(canvas.as_ref() as &web_sys::EventTarget)
|
||||
.add_event_listener_with_callback("mouseup", closure.as_ref().unchecked_ref())
|
||||
.unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user