Skip to main content

telar_ui_tree/
component.rs

1use platform_core::Event;
2
3use crate::render_node::RenderNode;
4
5#[derive(Debug, PartialEq)]
6pub enum EventResult {
7    Handled,
8    Ignored,
9}
10
11/// Imperative-state components re-render only when `on_event` returns `EventResult::Handled`; reactive-state components re-render automatically on signal change.
12pub trait Component: 'static {
13    fn view(&self) -> RenderNode;
14
15    fn on_event(&mut self, _event: &Event) -> EventResult {
16        EventResult::Ignored
17    }
18
19    /// Human-readable widget type name for the devtools tree inspector.
20    fn debug_name(&self) -> &'static str {
21        "Component"
22    }
23}
24
25impl Component for Box<dyn Component> {
26    fn view(&self) -> RenderNode {
27        (**self).view()
28    }
29
30    fn on_event(&mut self, event: &Event) -> EventResult {
31        (**self).on_event(event)
32    }
33
34    fn debug_name(&self) -> &'static str {
35        (**self).debug_name()
36    }
37}