Function freya::prelude::use_canvas_with_deps
source · pub fn use_canvas_with_deps<D, T>(
dependencies: D,
renderer_cb: impl FnMut(<D as Dependency>::Out) -> T + 'static,
) -> UseCanvaswhere
D: Dependency,
T: FnMut(&mut CanvasRunnerContext<'_>) + Sync + Send + 'static,
<D as Dependency>::Out: 'static,
Expand description
Register a rendering hook to gain access to the Canvas. Reactivity managed with manual dependencies.
§Usage
fn app() -> Element {
let (reference, size) = use_node_signal();
let mut value = use_signal(|| 0);
let platform = use_platform();
let canvas = use_canvas_with_deps(&value(), move |curr| {
platform.invalidate_drawing_area(size.peek().area);
platform.request_animation_frame();
move |ctx| {
// Draw using the canvas !
// use `curr`
}
});
rsx!(rect {
onclick: move |_| {
value += 1;
},
canvas_reference: canvas.attribute(),
reference,
width: "fill",
height: "fill",
})
}