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
36
37
38
39
40
41
42
43
44
use agui_core::{
    context::WidgetContext,
    layout::Layout,
    unit::{Color, Shape},
    widget::{BuildResult, WidgetBuilder, WidgetRef},
    Ref,
};
use agui_macros::Widget;

#[derive(Clone, Default)]
pub struct DrawableStyle {
    pub color: Color,
}

#[derive(Widget)]
pub struct Drawable {
    pub layout: Ref<Layout>,

    pub shape: Shape,
    pub style: Option<DrawableStyle>,

    pub child: WidgetRef,
}

impl Default for Drawable {
    fn default() -> Self {
        Self {
            layout: Ref::default(),

            shape: Shape::default(),
            style: Option::default(),

            child: WidgetRef::default(),
        }
    }
}

impl WidgetBuilder for Drawable {
    fn build(&self, ctx: &WidgetContext) -> BuildResult {
        ctx.set_layout(Ref::clone(&self.layout));

        (&self.child).into()
    }
}