ailloli_ui_runtime/component/
node.rs

1//! Lightweight legacy node model independent of widget views.
2
3use crate::element::Key;
4
5/// Coarse semantic category of a [`Node`].
6///
7/// # Examples
8///
9/// ```
10/// use ailloli_ui_runtime::component::NodeKind;
11/// assert_ne!(NodeKind::LayoutContainer, NodeKind::Control);
12/// ```
13#[derive(Debug, Clone, PartialEq)]
14pub enum NodeKind {
15    /// Node whose primary role is arranging children.
16    LayoutContainer,
17    /// Non-interactive drawing or content primitive.
18    Primitive,
19    /// Interactive control.
20    Control,
21}
22
23/// Minimal recursive node used by compatibility integrations.
24///
25/// This type stores no widget behavior, layout, or state. `key` is optional and
26/// scoped to reconciliation among siblings; `children` retain insertion order.
27///
28/// # Examples
29///
30/// ```
31/// use ailloli_ui_runtime::component::{Node, NodeKind};
32/// let node = Node::leaf(NodeKind::Primitive);
33/// assert!(node.key.is_none());
34/// assert!(node.children.is_empty());
35/// ```
36#[derive(Debug, Clone, PartialEq)]
37pub struct Node {
38    /// Coarse semantic category.
39    pub kind: NodeKind,
40    /// Optional stable sibling identity.
41    pub key: Option<Key>,
42    /// Ordered recursive children.
43    pub children: Vec<Node>,
44}
45
46/// Provides the operations defined for Node.
47impl Node {
48    /// Creates an unkeyed node with no children.
49    ///
50    /// # Examples
51    ///
52    /// ```
53    /// use ailloli_ui_runtime::component::{Node, NodeKind};
54    /// let node = Node::leaf(NodeKind::Control);
55    /// assert_eq!(node.kind, NodeKind::Control);
56    /// assert_eq!(node.children.len(), 0);
57    /// ```
58    pub fn leaf(kind: NodeKind) -> Self {
59        Self {
60            kind,
61            key: None,
62            children: Vec::new(),
63        }
64    }
65}