Skip to content
Discussion options

You must be logged in to vote

The new approach doesn't work as well with this kind of imperative style, it's true. It now separates "calling some view functions" from "building actual DOM elements" with an additional .build() method.

There are two decent ways to do it:

  1. Do it all in an imperative style and return a web-sys HtmlCanvasElement. (You won't be able to use this directly in the view, but you can mount it somewhere using web-sys)
fn prerender_image() -> HtmlCanvasElement {
    use wasm_bindgen::JsCast;
    use web_sys::HtmlCanvasElement;

    let canvas = html::canvas().build();
    let canvas = canvas.unchecked_into::<HtmlCanvasElement>();
    canvas.set_width(64);
    canvas.set_height(64);
    let ctx = c…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@janikarki
Comment options

Answer selected by janikarki
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants