Skip to content

Commit

Permalink
chore: Update use_canvas docs
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Jan 30, 2025
1 parent ef4da11 commit 26ee978
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions crates/hooks/src/use_canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,29 @@ impl UseCanvas {
/// ```rust,no_run
/// # use freya::prelude::*;
/// fn app() -> Element {
/// let value = use_signal(|| 0);
/// let (reference, size) = use_node_signal();
/// let mut value = use_signal(|| 0);
/// let platform = use_platform();
///
/// let canvas = use_canvas(move || {
/// let curr = value();
/// platform.invalidate_drawing_area(size.peek().area);
/// platform.request_animation_frame();
/// Box::new(move |ctx| {
/// // Draw using the canvas !
/// // use `curr`
/// })
/// });
///
/// rsx!(Canvas { canvas })
/// rsx!(rect {
/// onclick: move |_| {
/// value += 1;
/// },
/// canvas_reference: canvas.attribute(),
/// reference,
/// width: "fill",
/// height: "fill",
/// })
/// }
/// ```
pub fn use_canvas(renderer_cb: impl Fn() -> Box<CanvasRunner> + 'static) -> UseCanvas {
Expand All @@ -72,16 +84,28 @@ pub fn use_canvas(renderer_cb: impl Fn() -> Box<CanvasRunner> + 'static) -> UseC
/// ```rust,no_run
/// # use freya::prelude::*;
/// fn app() -> Element {
/// let value = use_signal(|| 0);
/// let (reference, size) = use_node_signal();
/// let mut value = use_signal(|| 0);
/// let platform = use_platform();
///
/// let canvas = use_canvas_with_deps(&value(), |curr| {
/// let canvas = use_canvas_with_deps(&value(), move |curr| {
/// platform.invalidate_drawing_area(size.peek().area);
/// platform.request_animation_frame();
/// Box::new(move |ctx| {
/// // Draw using the canvas !
/// // use `curr`
/// })
/// });
///
/// rsx!(Canvas { canvas })
/// rsx!(rect {
/// onclick: move |_| {
/// value += 1;
/// },
/// canvas_reference: canvas.attribute(),
/// reference,
/// width: "fill",
/// height: "fill",
/// })
/// }
/// ```
pub fn use_canvas_with_deps<D: Dependency>(
Expand Down

0 comments on commit 26ee978

Please sign in to comment.