orbit/
component_single.rs

1use crate::component::ComponentInstance;
2use crate::events::EventEmitter;
3use crate::state::StateContainer;
4use std::collections::HashMap;
5
6/// Context passed to components providing access to state and events
7#[derive(Clone, Debug)]
8pub struct Context {
9    /// State container for managing component and app state
10    #[allow(dead_code)]
11    state: StateContainer,
12
13    /// Event emitter for handling UI events
14    #[allow(dead_code)]
15    events: EventEmitter,
16}
17
18/// A node in the UI tree
19#[allow(dead_code)]
20pub struct Node {
21    /// Component instance
22    component: Option<ComponentInstance>,
23
24    /// Node attributes
25    attributes: HashMap<String, String>,
26
27    /// Child nodes
28    children: Vec<Node>,
29
30    /// Node ID
31    id: usize,
32}
33
34impl Node {
35    /// Get a reference to this node's children
36    pub fn children(&self) -> &[Node] {
37        &self.children
38    }
39
40    /// Get a mutable reference to this node's children
41    pub fn children_mut(&mut self) -> &mut Vec<Node> {
42        &mut self.children
43    }
44
45    /// Get this node's ID value
46    pub fn id_value(&self) -> usize {
47        self.id
48    }
49}
50
51impl Default for Node {
52    fn default() -> Self {
53        static mut NEXT_ID: usize = 0;
54        let id = unsafe {
55            let id = NEXT_ID;
56            NEXT_ID += 1;
57            id
58        };
59
60        Self {
61            component: None,
62            attributes: HashMap::new(),
63            children: Vec::new(),
64            id,
65        }
66    }
67}