2018-09-20 16:20:42 -07:00
|
|
|
# Paint Example
|
2018-09-14 00:41:58 +03:00
|
|
|
|
2018-09-20 17:54:06 -07:00
|
|
|
[View full source code][code] or [view the compiled example online][online]
|
2018-09-20 16:20:42 -07:00
|
|
|
|
2018-09-20 17:54:06 -07:00
|
|
|
[online]: https://rustwasm.github.io/wasm-bindgen/exbuild/paint/
|
2018-09-20 16:20:42 -07:00
|
|
|
[code]: https://github.com/rustwasm/wasm-bindgen/tree/master/examples/paint
|
2018-09-14 00:41:58 +03:00
|
|
|
|
2018-09-20 16:20:42 -07:00
|
|
|
A simple painting program.
|
2018-09-14 00:41:58 +03:00
|
|
|
|
|
|
|
## `Cargo.toml`
|
|
|
|
|
|
|
|
The `Cargo.toml` enables features necessary to work with the DOM, events and
|
|
|
|
2D canvas.
|
|
|
|
|
|
|
|
```toml
|
2018-09-20 16:20:42 -07:00
|
|
|
{{#include ../../../examples/paint/Cargo.toml}}
|
2018-09-14 00:41:58 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
## `src/lib.rs`
|
|
|
|
|
|
|
|
Creates the `<canvas>` element, applies a CSS style to it, adds it to the document,
|
|
|
|
get a 2D rendering context and adds listeners for mouse events.
|
|
|
|
|
|
|
|
```rust
|
2018-09-20 16:20:42 -07:00
|
|
|
{{#include ../../../examples/paint/src/lib.rs}}
|
2018-09-14 00:41:58 +03:00
|
|
|
```
|