1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use dioxus::prelude::{render, Element, Props, Scope};
use freya_elements::elements as dioxus_elements;

use freya_hooks::{use_applied_theme, CanvasTheme, CanvasThemeWith, UseCanvas};

/// [`Canvas`] component properties.
#[derive(Props, PartialEq)]
pub struct CanvasProps {
    /// Theme override.
    pub theme: Option<CanvasThemeWith>,
    /// The Canvas reference.
    pub canvas: UseCanvas,
}

/// Draw anything inside of this canvas.
///
/// # Props
/// See [`CanvasProps`].
///
#[allow(non_snake_case)]
pub fn Canvas(cx: Scope<CanvasProps>) -> Element {
    let CanvasTheme {
        width,
        height,
        background,
    } = use_applied_theme!(cx, &cx.props.theme, canvas);

    render!(rect {
        overflow: "clip",
        canvas_reference: cx.props.canvas.attribute(cx),
        background: "{background}",
        width: "{width}",
        height: "{height}"
    })
}