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::*;
use freya_elements::elements as dioxus_elements;

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

/// [`Canvas`] component properties.
#[derive(Props, Clone, 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(props: CanvasProps) -> Element {
    let CanvasTheme {
        width,
        height,
        background,
    } = use_applied_theme!(&props.theme, canvas);

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