maycoon_core/
widget.rs

1use vello::Scene;
2
3use maycoon_theme::id::WidgetId;
4use maycoon_theme::theme::Theme;
5
6use crate::app::info::AppInfo;
7use crate::app::update::Update;
8use crate::layout::{LayoutNode, StyleNode};
9use crate::state::State;
10
11/// The base trait for all widgets.
12pub trait Widget<S: State> {
13    /// Render the widget to the canvas.
14    fn render(
15        &mut self,
16        scene: &mut Scene,
17        theme: &mut dyn Theme,
18        info: &AppInfo,
19        layout_node: &LayoutNode,
20        state: &S,
21    );
22    /// Return the layout style node for layout computation.
23    fn layout_style(&mut self, state: &S) -> StyleNode;
24    /// Update the widget state with given info and layout. Returns if the app should be updated.
25    fn update(&mut self, layout: &LayoutNode, state: &mut S, info: &AppInfo) -> Update;
26    /// Return the widget id.
27    fn widget_id(&self) -> WidgetId;
28}