mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-25 14:12:13 +00:00
[examples] paint - port to rust 2018
This commit is contained in:
parent
e1d11fda95
commit
55f199ee77
@ -2,6 +2,7 @@
|
|||||||
name = "wasm-bindgen-paint"
|
name = "wasm-bindgen-paint"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["The wasm-bindgen Developers"]
|
authors = ["The wasm-bindgen Developers"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
extern crate js_sys;
|
|
||||||
extern crate wasm_bindgen;
|
|
||||||
extern crate web_sys;
|
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
@ -30,7 +26,7 @@ pub fn start() -> Result<(), JsValue> {
|
|||||||
context.begin_path();
|
context.begin_path();
|
||||||
context.move_to(event.offset_x() as f64, event.offset_y() as f64);
|
context.move_to(event.offset_x() as f64, event.offset_y() as f64);
|
||||||
pressed.set(true);
|
pressed.set(true);
|
||||||
}) as Box<FnMut(_)>);
|
}) as Box<dyn FnMut(_)>);
|
||||||
canvas.add_event_listener_with_callback("mousedown", closure.as_ref().unchecked_ref())?;
|
canvas.add_event_listener_with_callback("mousedown", closure.as_ref().unchecked_ref())?;
|
||||||
closure.forget();
|
closure.forget();
|
||||||
}
|
}
|
||||||
@ -44,7 +40,7 @@ pub fn start() -> Result<(), JsValue> {
|
|||||||
context.begin_path();
|
context.begin_path();
|
||||||
context.move_to(event.offset_x() as f64, event.offset_y() as f64);
|
context.move_to(event.offset_x() as f64, event.offset_y() as f64);
|
||||||
}
|
}
|
||||||
}) as Box<FnMut(_)>);
|
}) as Box<dyn FnMut(_)>);
|
||||||
canvas.add_event_listener_with_callback("mousemove", closure.as_ref().unchecked_ref())?;
|
canvas.add_event_listener_with_callback("mousemove", closure.as_ref().unchecked_ref())?;
|
||||||
closure.forget();
|
closure.forget();
|
||||||
}
|
}
|
||||||
@ -55,7 +51,7 @@ pub fn start() -> Result<(), JsValue> {
|
|||||||
pressed.set(false);
|
pressed.set(false);
|
||||||
context.line_to(event.offset_x() as f64, event.offset_y() as f64);
|
context.line_to(event.offset_x() as f64, event.offset_y() as f64);
|
||||||
context.stroke();
|
context.stroke();
|
||||||
}) as Box<FnMut(_)>);
|
}) as Box<dyn FnMut(_)>);
|
||||||
canvas.add_event_listener_with_callback("mouseup", closure.as_ref().unchecked_ref())?;
|
canvas.add_event_listener_with_callback("mouseup", closure.as_ref().unchecked_ref())?;
|
||||||
closure.forget();
|
closure.forget();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user