Crates.io | yew-canvas |
lib.rs | yew-canvas |
version | 0.2.4 |
source | src |
created_at | 2022-08-25 08:58:30.111165 |
updated_at | 2022-11-08 15:20:44.023443 |
description | A Canvas component is encapsulated. |
homepage | |
repository | https://github.com/1216892614/Yew-Canvas.rs |
max_upload_size | |
id | 652021 |
size | 21,321 |
Yew-Canvas.rs
is a simple Canvas component for Yew.
U can easily create a canvas with the context u need.
Just 3 Simple steps, if the context u need is CanvasRenderingContext2d
, do like this:
Get Yew-Canvas.rs
, HtmlCanvasElement
and context type!
#Cargo.toml
[dependencies]
yew="0.19"
yew-canvas="..."
[dependencies.web-sys]
version = "0.3.59"
features = ["HtmlCanvasElement", "CanvasRenderingContext2d"]
Create a Rander struct!
#[derive(Clone, PartialEq)]
struct Rander();
impl WithRander for Rander {
fn rand(self, canvas: &HtmlCanvasElement) {
//...
}
}
Return the component as VNode!
html!(
<Canvas<CanvasRenderingContext2d, Rander>
//Just use style, canvas can suit automaticly.
style="
width: 100%;
height: 100%;
"
rander={Box::new(Rander())}
/>
{"The browser is not supported."}
</Canvas<CanvasRenderingContext2d, Rander>>
)
Yew.rs
development environment in advance, the following is a Trunk
packaging example:cd ./examples/base-use
trunk serve
Yew-Canvas.rs
is dual licensed under the MIT license and the Apache License (Version 2.0).