euv_core/scene/node/struct.rs
1use super::*;
2
3/// Computed layout geometry cached on every scene node.
4#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
5pub struct LayoutBox {
6 /// Absolute border-box bounds in root logical coordinates.
7 #[get(type(copy))]
8 pub(crate) bounds: Rect,
9 /// Inner content-box bounds inside padding and border.
10 #[get(type(copy))]
11 pub(crate) content_bounds: Rect,
12 /// Intrinsic scrollable content size.
13 #[get(type(copy))]
14 pub(crate) content_size: Size,
15 /// Active scroll offset inside scroll containers.
16 #[get(type(copy))]
17 pub(crate) scroll_offset: Point,
18}
19
20/// Interactive visual state flags on a scene node.
21#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
22pub struct InteractionState {
23 /// Whether the node can receive keyboard focus.
24 #[get(type(copy))]
25 pub(crate) focusable: bool,
26 /// Whether the node currently holds keyboard focus.
27 #[get(type(copy))]
28 pub(crate) focused: bool,
29 /// Whether a pointer currently hovers over this node.
30 #[get(type(copy))]
31 pub(crate) hovered: bool,
32 /// Whether a pointer is actively pressed on this node.
33 #[get(type(copy))]
34 pub(crate) pressed: bool,
35}
36
37/// Theme-origin paint snapshot recorded the first time a node is restyled by an in-place theme remap.
38///
39/// Remapping always resolves from this origin snapshot (single hop) instead of chaining heuristic
40/// value matches across successive themes, so multi-hop theme switches never drift and round trips
41/// restore the exact original paint.
42#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
43pub struct ThemeBaseline {
44 /// Opaque 16-bit theme identifier (UI layer lookup index) the snapshot was captured under.
45 #[get(type(copy))]
46 pub(crate) origin_key: u16,
47 /// Paint (background, gradient, border, radii, shadow, focus ring) captured under the origin theme.
48 #[get(type(copy))]
49 pub(crate) paint: PaintStyle,
50 /// Text color captured under the origin theme.
51 #[get(type(copy))]
52 pub(crate) text_color: Color,
53 /// Effective ancestor-composited background behind this node under the origin theme.
54 #[get(type(copy))]
55 pub(crate) origin_eff_bg: Color,
56 /// Optional hover paint override captured under the origin theme.
57 #[get(type(copy))]
58 pub(crate) hover: Option<PaintStyle>,
59}
60
61/// Generation-guarded per-slot theme bookkeeping stored sparsely on `SceneTree`.
62#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
63pub(crate) struct ThemeNodeEntry {
64 /// Node generation the entry belongs to (stale entries are ignored and overwritten).
65 #[get(pub(crate), type(copy))]
66 #[set(pub(crate))]
67 pub(crate) generation: u32,
68 /// Whether a component reactively owns this node's themed paint (generic remaps skip it).
69 #[get(pub(crate), type(copy))]
70 #[set(pub(crate))]
71 pub(crate) owned: bool,
72 /// Theme-origin paint snapshot used by in-place remaps.
73 #[get(pub(crate), type(copy))]
74 #[set(pub(crate))]
75 pub(crate) baseline: Option<ThemeBaseline>,
76}
77
78/// Lazily allocated cold optional metadata boxed out of `SceneNode` to keep the hot node arena compact.
79#[derive(CustomDebug, Data, Default)]
80pub(crate) struct NodeExtras {
81 /// Optional hover paint override for zero-layout-cost hover feedback.
82 #[get(skip)]
83 pub(crate) hover_style: Option<PaintStyle>,
84 /// Optional reconciliation key for keyed list items.
85 #[get(skip)]
86 pub(crate) key: Option<String>,
87 /// Event callbacks attached to this node.
88 pub(crate) handlers: EventHandlers,
89 /// Optional reactive ownership scope disposed when this node is removed.
90 #[get(skip)]
91 pub(crate) scope: Option<Scope>,
92 /// Optional custom 2D canvas draw callback.
93 #[debug(skip)]
94 #[get(skip)]
95 pub(crate) canvas_painter: Option<CanvasDrawCallback>,
96 /// Optional explicit semantic accessibility metadata for screen readers and ARIA bridges.
97 #[get(skip)]
98 pub(crate) a11y: Option<A11yProps>,
99 /// Optional virtualized scroll metrics `(scroll_y, total_content_height)` for overlay scrollbar thumb accuracy.
100 #[get(skip)]
101 pub(crate) virtual_scroll: Option<(f32, f32)>,
102 /// Registered `Lifecycle` observers receiving mount, activate, freeze, resume, unmount, and destroy hooks.
103 #[debug(skip)]
104 #[get(skip)]
105 pub(crate) lifecycles: Vec<Rc<dyn Lifecycle>>,
106}
107
108/// Dense 8-byte SoA per-node metadata entry stored contiguously in `SceneTree` (8 nodes per 64B cache line).
109#[derive(Clone, Copy, Data, Debug, Default, Eq, New, PartialEq)]
110pub(crate) struct NodeMeta {
111 /// Generation tag matching live `NodeId` handles.
112 #[get(pub(crate), type(copy))]
113 #[get_mut(pub(crate))]
114 #[set(pub(crate))]
115 pub(crate) generation: u32,
116 /// Per-node structural bitflags (`NODE_FLAG_*`).
117 #[get(pub(crate), type(copy))]
118 #[get_mut(pub(crate))]
119 #[set(pub(crate))]
120 pub(crate) flags: u16,
121 /// Surgical dirty bitmask mirrored in SoA for cache-dense traversal.
122 #[get(pub(crate), type(copy))]
123 #[get_mut(pub(crate))]
124 #[set(pub(crate))]
125 pub(crate) dirty: u16,
126}
127
128/// Dense 24-byte SoA intrusive doubly-linked tree topology entry eliminating per-container `Vec<NodeId>` heap allocations.
129#[derive(Clone, Copy, Data, Debug, Eq, PartialEq)]
130pub(crate) struct NodeTopology {
131 /// Parent slot index (`NODE_INDEX_NONE` when detached or root).
132 #[get(pub(crate), type(copy))]
133 #[get_mut(pub(crate))]
134 #[set(pub(crate))]
135 pub(crate) parent: u32,
136 /// First direct child slot index (`NODE_INDEX_NONE` when leaf).
137 #[get(pub(crate), type(copy))]
138 #[get_mut(pub(crate))]
139 #[set(pub(crate))]
140 pub(crate) first_child: u32,
141 /// Last direct child slot index (`NODE_INDEX_NONE` when leaf) enabling O(1) append and reverse iteration.
142 #[get(pub(crate), type(copy))]
143 #[get_mut(pub(crate))]
144 #[set(pub(crate))]
145 pub(crate) last_child: u32,
146 /// Next sibling slot index (`NODE_INDEX_NONE` at tail).
147 #[get(pub(crate), type(copy))]
148 #[get_mut(pub(crate))]
149 #[set(pub(crate))]
150 pub(crate) next_sibling: u32,
151 /// Previous sibling slot index (`NODE_INDEX_NONE` at head).
152 #[get(pub(crate), type(copy))]
153 #[get_mut(pub(crate))]
154 #[set(pub(crate))]
155 pub(crate) prev_sibling: u32,
156 /// Cached direct child count for O(1) `child_count` and `has_children` queries.
157 #[get(pub(crate), type(copy))]
158 #[get_mut(pub(crate))]
159 #[set(pub(crate))]
160 pub(crate) child_count: u32,
161}
162
163/// Retained scene node stored contiguously inside `SceneTree`.
164#[derive(CustomDebug, Data)]
165pub struct SceneNode {
166 /// Generation tag matching live `NodeId` handles.
167 #[get(type(copy))]
168 #[get_mut(pub(crate))]
169 #[set(pub(crate))]
170 pub(crate) generation: u32,
171 /// Whether this arena slot is currently occupied.
172 #[get(type(copy))]
173 #[get_mut(pub(crate))]
174 #[set(pub(crate))]
175 pub(crate) alive: bool,
176 /// Compact structural flags (`NODE_FLAG_ALIVE`, `NODE_FLAG_HAS_EXTRAS`, `NODE_FLAG_HAS_LIFECYCLE`, `NODE_FLAG_HAS_SCOPE`).
177 #[get(type(copy))]
178 #[get_mut(pub(crate))]
179 #[set(pub(crate))]
180 pub(crate) node_flags: u16,
181 /// Semantic kind and node-specific payload.
182 pub(crate) kind: NodeKind,
183 /// Compiled layout, paint, and typography style.
184 #[get(type(copy))]
185 pub(crate) style: Style,
186 /// Computed layout box and scroll offsets.
187 #[get(type(copy))]
188 pub(crate) layout_box: LayoutBox,
189 /// Cached previous layout constraints for clean-subtree O(1) skipping.
190 #[get(skip)]
191 #[get_mut(pub(crate))]
192 #[set(pub(crate))]
193 pub(crate) last_constraint: Option<AvailableSpace>,
194 /// Surgical dirty bitmask.
195 #[get(type(copy))]
196 pub(crate) dirty: DirtyFlags,
197 /// Parent node handle if attached to the tree.
198 #[get(skip)]
199 pub(crate) parent: Option<NodeId>,
200 /// Interactive focus/hover/pressed state.
201 #[get(type(copy))]
202 pub(crate) interaction: InteractionState,
203 /// Lazily boxed cold optional metadata (handlers, hover style, a11y, lifecycles, scope, canvas, key, virtual scroll).
204 #[debug(skip)]
205 #[get(skip)]
206 #[get_mut(skip)]
207 #[set(skip)]
208 pub(crate) extras: Option<Box<NodeExtras>>,
209}