pub const canvas_reference: (&'static str, Option<&'static str>, bool);
Expand description

Attach a canvas reference created from the use_canvas or use_canvas_with_deps hooks to enable drawing to an element.

This attribute allows you to bind a canvas context to a Freya element, giving you the ability to perform custom rendering operations.

§Example

fn app() -> Element {
    let (reference, size) = use_node_signal();
    let platform = use_platform();

    let canvas = use_canvas(move || {
        platform.invalidate_drawing_area(size.peek().area);
        platform.request_animation_frame();
        move |ctx| {
            // Custom drawing code here,
            // you will need to add skia as a dependency and look into how to use a skia canvas
        }
    });

    rsx!(
        rect {
            background: "white",
            width: "300",
            height: "200",
            canvas_reference: canvas.attribute(),
            reference,
        }
    )
}