euv_core/scene/tree/struct.rs
1use super::*;
2
3/// Flat generation-indexed arena holding the entire retained UI scene graph with dense SoA metadata and intrusive child topology.
4#[derive(CustomDebug, Data)]
5pub struct SceneTree {
6 /// Contiguous node storage vector.
7 pub(crate) nodes: Vec<SceneNode>,
8 /// Dense 8-byte SoA metadata parallel to `nodes` (generation, structural flags, dirty mask).
9 #[get(pub(crate))]
10 #[get_mut(pub(crate))]
11 #[set(skip)]
12 pub(crate) meta: Vec<NodeMeta>,
13 /// Dense 24-byte SoA intrusive doubly-linked tree topology parallel to `nodes` (0 `Vec<NodeId>` heap allocations).
14 #[get(pub(crate))]
15 #[get_mut(pub(crate))]
16 #[set(skip)]
17 pub(crate) topology: Vec<NodeTopology>,
18 /// Dense 32-byte SoA compact paint style array parallel to `nodes`.
19 #[get(pub(crate))]
20 #[get_mut(pub(crate))]
21 #[set(skip)]
22 pub(crate) compact_paints: Vec<CompactPaintStyle>,
23 /// Sparse slot-recycled table of rare paint effects (`Shadow`, `LinearGradient`, `Transform2D`, `focus_ring`, `backdrop_blur`).
24 #[get(pub(crate))]
25 #[get_mut(pub(crate))]
26 #[set(skip)]
27 pub(crate) effect_table: EffectTable,
28 /// Recycled slot indices for O(1) node allocation.
29 #[get(pub(crate))]
30 #[get_mut(pub(crate))]
31 #[set(pub(crate))]
32 pub(crate) free_list: Vec<u32>,
33 /// Incrementally maintained count of live nodes for O(1) `live_node_count()`.
34 #[get(pub(crate), type(copy))]
35 #[get_mut(pub(crate))]
36 #[set(pub(crate))]
37 pub(crate) live_count: usize,
38 /// Incrementally maintained count of attached `Lifecycle` observers for O(1) zero-lifecycle traversal skipping.
39 #[get(pub(crate), type(copy))]
40 #[get_mut(pub(crate))]
41 #[set(pub(crate))]
42 pub(crate) live_lifecycle_count: usize,
43 /// Root scene node handle.
44 #[get(type(copy))]
45 pub(crate) root: NodeId,
46 /// Focus, hover, and pointer-press tracking state.
47 #[get(type(copy))]
48 pub(crate) focus: FocusManager,
49 /// Monotonic structural/visual mutation counter.
50 #[get(type(copy))]
51 pub(crate) revision: u64,
52 /// Active paint/transform node transitions ticked on every frame until settled.
53 pub(crate) transitions: Vec<NodeTransition>,
54 /// Blinking visibility state of the focused text input caret (`true` = visible phase).
55 #[get(type(copy))]
56 pub(crate) caret_visible: bool,
57 /// Incrementally maintained registry of live `NodeKind::Portal` and `Position::Fixed` nodes.
58 #[get(skip)]
59 #[get_mut(pub(crate))]
60 #[set(skip)]
61 pub(crate) portal_nodes: Vec<NodeId>,
62 /// Incrementally maintained registry of live `Overflow::Scroll` container nodes.
63 #[get(skip)]
64 #[get_mut(pub(crate))]
65 #[set(skip)]
66 pub(crate) scroll_nodes: Vec<NodeId>,
67 /// Bounded list of nodes marked paint/scroll dirty since the last `collect_paint_damage` pass.
68 #[get(pub(crate))]
69 #[get_mut(pub(crate))]
70 #[set(pub(crate))]
71 pub(crate) dirty_paint_nodes: Vec<NodeId>,
72 /// Flag raised when structural/layout mutations or >64 dirty nodes require full viewport damage.
73 #[get(pub(crate), type(copy))]
74 #[get_mut(pub(crate))]
75 #[set(pub(crate))]
76 pub(crate) full_damage_pending: bool,
77 /// Flag raised when one or more layout/children/text mutations occurred since the last damage collection.
78 #[get(pub(crate), type(copy))]
79 #[get_mut(pub(crate))]
80 #[set(pub(crate))]
81 pub(crate) layout_damage_pending: bool,
82 /// Flag raised when `dirty_paint_nodes` exceeded `DIRTY_PAINT_FULL_THRESHOLD` since the last collection.
83 #[get(pub(crate), type(copy))]
84 #[get_mut(pub(crate))]
85 #[set(pub(crate))]
86 pub(crate) full_damage_overflow: bool,
87 /// Number of newly allocated nodes created since the last damage collection (promotes to overflow above threshold).
88 #[get(pub(crate), type(copy))]
89 #[get_mut(pub(crate))]
90 #[set(pub(crate))]
91 pub(crate) created_since_damage: usize,
92 /// Pre-mutation conservative logical screen rectangles for disposed, reparented, or shrinking-halo nodes.
93 #[get(pub(crate))]
94 #[get_mut(pub(crate))]
95 #[set(pub(crate))]
96 pub(crate) extra_logical_damage: Vec<Rect>,
97 /// Active native text selection state on a selectable `NodeKind::Text` node, if any.
98 #[get(skip)]
99 #[get_mut(skip)]
100 #[set(skip)]
101 pub(crate) text_selection: Option<SelectionState>,
102 /// Registry of live nodes with active backdrop-blur radii `(node_id, blur_radius)` for effect-dependency damage propagation.
103 #[get(pub(crate))]
104 #[get_mut(pub(crate))]
105 #[set(skip)]
106 pub(crate) backdrop_blur_nodes: Vec<(NodeId, f32)>,
107 /// Cumulative count of genuine layout-invalidating mutations (`DIRTY_LAYOUT`, `DIRTY_CHILDREN`, `DIRTY_TEXT`, node creation).
108 #[get(type(copy))]
109 #[get_mut(skip)]
110 #[set(pub(crate))]
111 pub(crate) layout_invalidations: u64,
112 /// Whether the most recent `collect_surgical_paint_damage` pass observed only composite/scroll changes with zero layout or paint mutations.
113 #[get(pub(crate), type(copy))]
114 #[get_mut(skip)]
115 #[set(pub(crate))]
116 pub(crate) last_collect_composite_only: bool,
117 /// Sparse generation-guarded theme ownership and origin snapshots keyed by arena slot index.
118 #[get(skip)]
119 #[get_mut(skip)]
120 #[set(skip)]
121 pub(crate) theme_entries: HashMap<u32, ThemeNodeEntry>,
122 /// Dense per-node monotonic paint epoch parallel to `nodes` for O(1) `PaintFragmentCache` invalidation.
123 #[get(pub(crate))]
124 #[get_mut(pub(crate))]
125 #[set(skip)]
126 pub(crate) paint_epochs: Vec<u32>,
127 /// Flag raised when `LayoutEngine` skips a `Display::None` node carrying `DIRTY_SUBTREE_LAYOUT` so `mark_dirty` never breaks early on stale descendant bits.
128 #[get(pub(crate), type(copy))]
129 #[get_mut(skip)]
130 #[set(pub(crate))]
131 pub(crate) has_stale_hidden_dirty: bool,
132}
133
134/// Zero-allocation double-ended iterator over a node's direct children in `SceneTree`'s intrusive SoA topology.
135#[derive(Clone, Debug)]
136pub struct SceneChildIter<'a> {
137 /// Shared slice of scene metadata carrying slot generations.
138 pub(crate) meta: &'a [NodeMeta],
139 /// Shared slice of intrusive sibling links.
140 pub(crate) topology: &'a [NodeTopology],
141 /// Current forward cursor slot index (`NODE_INDEX_NONE` when exhausted).
142 pub(crate) head: u32,
143 /// Current backward cursor slot index (`NODE_INDEX_NONE` when exhausted).
144 pub(crate) tail: u32,
145 /// Remaining unyielded direct children count.
146 pub(crate) remaining: usize,
147}
148
149/// Shared scene storage pairing interior-mutable `SceneTree` access with a zero-steady-state-allocation deferred write queue.
150#[derive(CustomDebug)]
151pub(crate) struct SceneHandleInner {
152 /// Interior-mutable retained UI scene tree.
153 pub(crate) tree: RefCell<SceneTree>,
154 /// Fast-path flag indicating at least one deferred mutation is queued (avoids `RefCell` touch in steady state).
155 pub(crate) has_deferred: Cell<bool>,
156 /// Lazily populated queue of re-entrant scene mutations deferred while `tree` is actively borrowed.
157 #[debug(skip)]
158 pub(crate) deferred_writes: RefCell<Vec<DeferredSceneWrite>>,
159}
160
161/// RAII guard tracking active `SceneTree` borrow nesting depth on the current thread.
162#[derive(Debug)]
163pub(crate) struct SceneBorrowGuard;
164
165/// Shared handle wrapping a `SceneTree` so reactive `Effect` closures can patch nodes directly.
166#[derive(Clone, CustomDebug)]
167pub struct SceneHandle {
168 /// Shared interior-mutable scene storage and deferred mutation queue.
169 pub(crate) inner: Rc<SceneHandleInner>,
170}
171
172/// Ambient framework-managed UI context binding the active `SceneHandle`, responsive signals, and platform metadata.
173#[derive(Clone, CustomDebug, Data)]
174pub struct Context {
175 /// Shared scene tree handle for creating and binding nodes.
176 pub(crate) scene: SceneHandle,
177 /// Current viewport logical breakpoint signal for responsive layouts.
178 #[get(type(copy))]
179 pub(crate) breakpoint: Signal<Breakpoint>,
180 /// Current logical viewport dimensions signal updated immediately on window resize.
181 #[get(type(copy))]
182 pub(crate) viewport_size: Signal<Size>,
183 /// Current OS/app theme mode signal (`Light` / `Dark`).
184 #[get(type(copy))]
185 pub(crate) theme_mode: Signal<ThemeMode>,
186 /// Active platform kind for capability-aware adaptation.
187 #[get(type(copy))]
188 pub(crate) platform: PlatformKind,
189 /// Active safe-area insets signal.
190 #[get(type(copy))]
191 pub(crate) safe_area: Signal<SafeAreaInsets>,
192 /// Reactive stream of recognized cross-platform gestures (`Tap`, `DoubleTap`, `LongPress`, `Swipe*`, `Pan`, `Pinch`).
193 #[get(type(copy))]
194 pub(crate) gesture: Signal<Option<GestureEvent>>,
195 /// Live horizontal touch-swipe drag displacement in logical pixels (`0.0` when idle) for interactive page-swipe feedback.
196 #[get(type(copy))]
197 pub(crate) swipe_drag_offset: Signal<f32>,
198 /// Monotonic counter incremented on OS Back button / Escape / edge-back triggers for unified overlay & router stack dismissal.
199 #[get(type(copy))]
200 pub(crate) system_back: Signal<u64>,
201 /// Shared dynamic update hub enabling ambient component-level and page-level live updates.
202 pub(crate) dynamic_hub: DynamicUpdateHub,
203 /// Optional target FPS cap across all platforms (`None` = unlimited maximum FPS by default).
204 #[get(type(copy))]
205 pub(crate) fps_limit: Signal<Option<u32>>,
206 /// Smoothed live rendered frames-per-second telemetry signal.
207 #[get(type(copy))]
208 pub(crate) live_fps: Signal<f32>,
209 /// Idle-aware active presented frames-per-second signal (`0.0` while idle).
210 #[get(type(copy))]
211 pub(crate) present_fps: Signal<f32>,
212 /// Reactive flag indicating whether the frame loop is currently idle (`true` when skipping clean frames).
213 #[get(type(copy))]
214 pub(crate) is_idle: Signal<bool>,
215 /// Native hardware display refresh rate in Hertz reported by the active OS/browser host.
216 #[get(type(copy))]
217 pub(crate) display_refresh_rate: Signal<f32>,
218 /// Live snapshot of all currently active touch/pointer contacts `(pointer_id, position)` for multi-touch UIs.
219 #[get(type(copy))]
220 pub(crate) active_touches: Signal<Vec<(u64, Point)>>,
221 /// Reactive flag raised when the application requests graceful termination (e.g. double-back-to-exit at root).
222 #[get(type(copy))]
223 pub(crate) exit_requested: Signal<bool>,
224 /// Canonical cross-platform application lifecycle state signal (`Active`, `Inactive`, `Background`, `Terminated`).
225 #[get(type(copy))]
226 pub(crate) app_state: Signal<AppState>,
227 /// Live network reachability status signal (`Online`, `Offline`, `Wifi`, `Cellular`, `Unknown`).
228 #[get(type(copy))]
229 pub(crate) network_status: Signal<NetworkStatus>,
230 /// Whether the soft virtual keyboard / IME is currently presented.
231 #[get(type(copy))]
232 pub(crate) keyboard_visible: Signal<bool>,
233 /// Current soft virtual keyboard height in logical pixels (`0.0` when hidden).
234 #[get(type(copy))]
235 pub(crate) keyboard_height: Signal<f32>,
236 /// Current screen or window orientation signal.
237 #[get(type(copy))]
238 pub(crate) orientation: Signal<ScreenOrientation>,
239 /// Whether OS battery saver / low-power mode is currently enabled.
240 #[get(type(copy))]
241 pub(crate) low_power_mode: Signal<bool>,
242 /// Active OS/browser preferred BCP-47 locale string signal.
243 #[get(type(copy))]
244 pub(crate) locale: Signal<String>,
245 /// Whether the primary application window currently holds keyboard/input focus.
246 #[get(type(copy))]
247 pub(crate) window_focused: Signal<bool>,
248 /// Reactive flag indicating whether immersive fullscreen mode is active across app chrome and OS system bars.
249 #[get(type(copy))]
250 #[set(skip)]
251 pub(crate) immersive_fullscreen: Signal<bool>,
252 /// Live screen-aligned 6-DOF gravity, linear acceleration, and gyroscope sensor sample signal.
253 #[get(type(copy))]
254 pub(crate) device_motion: Signal<DeviceMotionSample>,
255 /// Shared reference-counted context lifetime owner storing clock, fullscreen depth, and owned signals disposed on final drop.
256 #[debug(skip)]
257 #[get(skip)]
258 #[get_mut(skip)]
259 #[set(skip)]
260 pub(crate) shared: Rc<ContextShared>,
261}
262
263/// Shared interior-mutable runtime metadata and signal ownership table disposed automatically when the last `Context` clone drops.
264#[derive(Debug)]
265pub(crate) struct ContextShared {
266 /// Nested immersive fullscreen entry counter enabling balanced RAII enter/exit calls.
267 pub(crate) fullscreen_depth: Cell<u32>,
268 /// Monotonic runtime clock in milliseconds advanced deterministically by `App` frame steps.
269 pub(crate) clock_ms: Cell<u64>,
270 /// Detached reactive signals created by `Context::new` and disposed on final drop to guarantee zero lifecycle leak.
271 pub(crate) owned_signals: [SignalId; 24],
272 /// Reactive runtime epoch active when `owned_signals` were allocated.
273 pub(crate) runtime_epoch: u64,
274}
275
276/// RAII scope guard restoring the previous ambient `Context` on drop.
277#[derive(CustomDebug, New)]
278pub struct ContextGuard {
279 /// Previously bound ambient context to restore when leaving scope.
280 pub(crate) previous: Option<Context>,
281}