1use crate::app::context::AppContext;
2use crate::app::info::AppInfo;
3use crate::app::update::Update;
4use crate::layout::{LayoutNode, LayoutStyle, StyleNode};
5use crate::signal::MaybeSignal;
6use crate::vgi::Scene;
7use maycoon_theme::id::WidgetId;
8use maycoon_theme::theme::Theme;
9
10pub type BoxedWidget = Box<dyn Widget>;
12
13pub trait Widget {
15 fn render(
17 &mut self,
18 scene: &mut dyn Scene,
19 theme: &mut dyn Theme,
20 layout_node: &LayoutNode,
21 info: &AppInfo,
22 context: AppContext,
23 );
24
25 fn layout_style(&self) -> StyleNode;
27
28 fn update(&mut self, layout: &LayoutNode, context: AppContext, info: &AppInfo) -> Update;
30
31 fn widget_id(&self) -> WidgetId;
33}
34
35pub trait WidgetChildExt {
37 fn set_child(&mut self, child: impl Widget + 'static);
39
40 fn with_child(mut self, child: impl Widget + 'static) -> Self
42 where
43 Self: Sized,
44 {
45 self.set_child(child);
46 self
47 }
48}
49
50pub trait WidgetChildrenExt {
52 fn set_children(&mut self, children: Vec<BoxedWidget>);
54
55 fn with_children(mut self, children: Vec<BoxedWidget>) -> Self
57 where
58 Self: Sized,
59 {
60 self.set_children(children);
61 self
62 }
63
64 fn add_child(&mut self, child: impl Widget + 'static);
66
67 fn with_child(mut self, child: impl Widget + 'static) -> Self
69 where
70 Self: Sized,
71 {
72 self.add_child(child);
73 self
74 }
75}
76
77pub trait WidgetLayoutExt {
79 fn set_layout_style(&mut self, layout_style: impl Into<MaybeSignal<LayoutStyle>>);
81
82 fn with_layout_style(mut self, layout_style: impl Into<MaybeSignal<LayoutStyle>>) -> Self
84 where
85 Self: Sized,
86 {
87 self.set_layout_style(layout_style);
88 self
89 }
90}