Function freya::prelude::use_canvas

source ·
pub fn use_canvas(
    renderer_cb: impl Fn() -> Box<dyn Fn(&Canvas, &mut RCHandle<skia_textlayout_FontCollection>, Rect<f32, Measure>, f32) + Sync + Send> + 'static
) -> UseCanvas
Expand description

Register a rendering hook to gain access to the Canvas. Reactivity managed through signals.

§Usage

fn app() -> Element {
    let value = use_signal(|| 0);

    let canvas = use_canvas(move || {
        let curr = value();
        Box::new(move |canvas, font_collection, area, scale_factor| {
            // Draw using the canvas !
            // use `curr`
        })
    });

    rsx!(Canvas { canvas })
}