Skip to main content

anathema_widgets/nodes/
component.rs

1use anathema_state::StateId;
2use anathema_store::storage::strings::StringId;
3use anathema_templates::blueprints::Blueprint;
4use anathema_templates::{AssocEventMapping, ComponentBlueprintId};
5
6use crate::WidgetId;
7use crate::components::{AnyComponent, ComponentKind};
8
9#[derive(Debug)]
10pub struct Component<'bp> {
11    pub name: &'bp str,
12    pub name_id: StringId,
13    pub body: &'bp [Blueprint],
14    pub dyn_component: Box<dyn AnyComponent>,
15    pub state_id: StateId,
16    /// Used to identify the component in the component registry.
17    /// This id will not be unique for prototypes
18    pub component_id: ComponentBlueprintId,
19    pub widget_id: WidgetId,
20    pub parent: Option<WidgetId>,
21    pub kind: ComponentKind,
22    pub assoc_functions: &'bp [AssocEventMapping],
23    pub tabindex: u16,
24}
25
26impl<'bp> Component<'bp> {
27    pub fn new(
28        name: &'bp str,
29        name_id: StringId,
30        body: &'bp [Blueprint],
31        dyn_component: Box<dyn AnyComponent>,
32        state_id: StateId,
33        component_id: ComponentBlueprintId,
34        widget_id: WidgetId,
35        kind: ComponentKind,
36        assoc_functions: &'bp [AssocEventMapping],
37        parent: Option<WidgetId>,
38    ) -> Self {
39        Self {
40            name,
41            name_id,
42            body,
43            dyn_component,
44            state_id,
45            component_id,
46            widget_id,
47            kind,
48            assoc_functions,
49            parent,
50            tabindex: 0,
51        }
52    }
53
54    pub(crate) fn state_id(&self) -> StateId {
55        self.state_id
56    }
57}