euv_core/scene/tree/struct.rs
1use super::*;
2
3/// Flat generation-indexed arena holding the entire retained UI scene graph.
4#[derive(CustomDebug, Data)]
5pub struct SceneTree {
6 /// Contiguous node storage vector.
7 pub(crate) nodes: Vec<SceneNode>,
8 /// Recycled slot indices for O(1) node allocation.
9 #[get(pub(crate))]
10 #[get_mut(pub(crate))]
11 #[set(pub(crate))]
12 pub(crate) free_list: Vec<u32>,
13 /// Incrementally maintained count of live nodes for O(1) `live_node_count()`.
14 #[get(pub(crate), type(copy))]
15 #[get_mut(pub(crate))]
16 #[set(pub(crate))]
17 pub(crate) live_count: usize,
18 /// Root scene node handle.
19 #[get(type(copy))]
20 pub(crate) root: NodeId,
21 /// Focus, hover, and pointer-press tracking state.
22 #[get(type(copy))]
23 pub(crate) focus: FocusManager,
24 /// Monotonic structural/visual mutation counter.
25 #[get(type(copy))]
26 pub(crate) revision: u64,
27 /// Active paint/transform node transitions ticked on every frame until settled.
28 pub(crate) transitions: Vec<NodeTransition>,
29 /// Blinking visibility state of the focused text input caret (`true` = visible phase).
30 #[get(type(copy))]
31 pub(crate) caret_visible: bool,
32 /// Incrementally maintained registry of live `NodeKind::Portal` and `Position::Fixed` nodes.
33 #[get(skip)]
34 #[get_mut(pub(crate))]
35 #[set(skip)]
36 pub(crate) portal_nodes: Vec<NodeId>,
37 /// Bounded list of nodes marked paint/scroll dirty since the last `collect_paint_damage` pass.
38 #[get(pub(crate))]
39 #[get_mut(pub(crate))]
40 #[set(pub(crate))]
41 pub(crate) dirty_paint_nodes: Vec<NodeId>,
42 /// Flag raised when structural/layout mutations or >64 dirty nodes require full viewport damage.
43 #[get(pub(crate), type(copy))]
44 #[get_mut(pub(crate))]
45 #[set(pub(crate))]
46 pub(crate) full_damage_pending: bool,
47 /// Flag raised when one or more layout/children/text mutations occurred since the last damage collection.
48 #[get(pub(crate), type(copy))]
49 #[get_mut(pub(crate))]
50 #[set(pub(crate))]
51 pub(crate) layout_damage_pending: bool,
52 /// Flag raised when `dirty_paint_nodes` exceeded `DIRTY_PAINT_FULL_THRESHOLD` since the last collection.
53 #[get(pub(crate), type(copy))]
54 #[get_mut(pub(crate))]
55 #[set(pub(crate))]
56 pub(crate) full_damage_overflow: bool,
57 /// Number of newly allocated nodes created since the last damage collection (promotes to overflow above threshold).
58 #[get(pub(crate), type(copy))]
59 #[get_mut(pub(crate))]
60 #[set(pub(crate))]
61 pub(crate) created_since_damage: usize,
62 /// Pre-mutation conservative logical screen rectangles for disposed, reparented, or shrinking-halo nodes.
63 #[get(pub(crate))]
64 #[get_mut(pub(crate))]
65 #[set(pub(crate))]
66 pub(crate) extra_logical_damage: Vec<Rect>,
67 /// Active native text selection state on a selectable `NodeKind::Text` node, if any.
68 #[get(skip)]
69 #[get_mut(skip)]
70 #[set(skip)]
71 pub(crate) text_selection: Option<SelectionState>,
72 /// Registry of live nodes with active backdrop-blur radii `(node_id, blur_radius)` for effect-dependency damage propagation.
73 #[get(pub(crate))]
74 #[get_mut(pub(crate))]
75 #[set(skip)]
76 pub(crate) backdrop_blur_nodes: Vec<(NodeId, f32)>,
77 /// Cumulative count of genuine layout-invalidating mutations (`DIRTY_LAYOUT`, `DIRTY_CHILDREN`, `DIRTY_TEXT`, node creation).
78 #[get(type(copy))]
79 #[get_mut(skip)]
80 #[set(pub(crate))]
81 pub(crate) layout_invalidations: u64,
82 /// Whether the most recent `collect_surgical_paint_damage` pass observed only composite/scroll changes with zero layout or paint mutations.
83 #[get(pub(crate), type(copy))]
84 #[get_mut(skip)]
85 #[set(pub(crate))]
86 pub(crate) last_collect_composite_only: bool,
87}
88
89/// Shared handle wrapping a `SceneTree` so reactive `Effect` closures can patch nodes directly.
90#[derive(Clone, CustomDebug)]
91pub struct SceneHandle {
92 /// Shared interior-mutable reference to the thread-local scene tree.
93 pub(crate) inner: Rc<RefCell<SceneTree>>,
94}
95
96/// Ambient framework-managed UI context binding the active `SceneHandle`, responsive signals, and platform metadata.
97#[derive(Clone, CustomDebug, Data)]
98pub struct Context {
99 /// Shared scene tree handle for creating and binding nodes.
100 pub(crate) scene: SceneHandle,
101 /// Current viewport logical breakpoint signal for responsive layouts.
102 #[get(type(copy))]
103 pub(crate) breakpoint: Signal<Breakpoint>,
104 /// Current logical viewport dimensions signal updated immediately on window resize.
105 #[get(type(copy))]
106 pub(crate) viewport_size: Signal<Size>,
107 /// Current OS/app theme mode signal (`Light` / `Dark`).
108 #[get(type(copy))]
109 pub(crate) theme_mode: Signal<ThemeMode>,
110 /// Active platform kind for capability-aware adaptation.
111 #[get(type(copy))]
112 pub(crate) platform: PlatformKind,
113 /// Active safe-area insets signal.
114 #[get(type(copy))]
115 pub(crate) safe_area: Signal<SafeAreaInsets>,
116 /// Reactive stream of recognized cross-platform gestures (`Tap`, `DoubleTap`, `LongPress`, `Swipe*`, `Pan`, `Pinch`).
117 #[get(type(copy))]
118 pub(crate) gesture: Signal<Option<GestureEvent>>,
119 /// Live horizontal touch-swipe drag displacement in logical pixels (`0.0` when idle) for interactive page-swipe feedback.
120 #[get(type(copy))]
121 pub(crate) swipe_drag_offset: Signal<f32>,
122 /// Monotonic counter incremented on OS Back button / Escape / edge-back triggers for unified overlay & router stack dismissal.
123 #[get(type(copy))]
124 pub(crate) system_back: Signal<u64>,
125 /// Shared dynamic update hub enabling ambient component-level and page-level live updates.
126 pub(crate) dynamic_hub: DynamicUpdateHub,
127 /// Optional target FPS cap across all platforms (`None` = unlimited maximum FPS by default).
128 #[get(type(copy))]
129 pub(crate) fps_limit: Signal<Option<u32>>,
130 /// Smoothed live rendered frames-per-second telemetry signal.
131 #[get(type(copy))]
132 pub(crate) live_fps: Signal<f32>,
133 /// Idle-aware active presented frames-per-second signal (`0.0` while idle).
134 #[get(type(copy))]
135 pub(crate) present_fps: Signal<f32>,
136 /// Reactive flag indicating whether the frame loop is currently idle (`true` when skipping clean frames).
137 #[get(type(copy))]
138 pub(crate) is_idle: Signal<bool>,
139 /// Native hardware display refresh rate in Hertz reported by the active OS/browser host.
140 #[get(type(copy))]
141 pub(crate) display_refresh_rate: Signal<f32>,
142 /// Live snapshot of all currently active touch/pointer contacts `(pointer_id, position)` for multi-touch UIs.
143 #[get(type(copy))]
144 pub(crate) active_touches: Signal<Vec<(u64, Point)>>,
145 /// Reactive flag raised when the application requests graceful termination (e.g. double-back-to-exit at root).
146 #[get(type(copy))]
147 pub(crate) exit_requested: Signal<bool>,
148 /// Canonical cross-platform application lifecycle state signal (`Active`, `Inactive`, `Background`, `Terminated`).
149 #[get(type(copy))]
150 pub(crate) app_state: Signal<AppState>,
151 /// Live network reachability status signal (`Online`, `Offline`, `Wifi`, `Cellular`, `Unknown`).
152 #[get(type(copy))]
153 pub(crate) network_status: Signal<NetworkStatus>,
154 /// Whether the soft virtual keyboard / IME is currently presented.
155 #[get(type(copy))]
156 pub(crate) keyboard_visible: Signal<bool>,
157 /// Current soft virtual keyboard height in logical pixels (`0.0` when hidden).
158 #[get(type(copy))]
159 pub(crate) keyboard_height: Signal<f32>,
160 /// Current screen or window orientation signal.
161 #[get(type(copy))]
162 pub(crate) orientation: Signal<ScreenOrientation>,
163 /// Whether OS battery saver / low-power mode is currently enabled.
164 #[get(type(copy))]
165 pub(crate) low_power_mode: Signal<bool>,
166 /// Active OS/browser preferred BCP-47 locale string signal.
167 #[get(type(copy))]
168 pub(crate) locale: Signal<String>,
169 /// Whether the primary application window currently holds keyboard/input focus.
170 #[get(type(copy))]
171 pub(crate) window_focused: Signal<bool>,
172 /// Reactive flag indicating whether immersive fullscreen mode is active across app chrome and OS system bars.
173 #[get(type(copy))]
174 #[set(skip)]
175 pub(crate) immersive_fullscreen: Signal<bool>,
176 /// Nested immersive fullscreen entry counter enabling balanced RAII enter/exit calls.
177 #[debug(skip)]
178 #[get(skip)]
179 #[get_mut(skip)]
180 #[set(skip)]
181 pub(crate) fullscreen_depth: Rc<Cell<u32>>,
182 /// Monotonic runtime clock in milliseconds advanced deterministically by `App` frame steps.
183 #[debug(skip)]
184 #[get(skip)]
185 pub(crate) clock_ms: Rc<Cell<u64>>,
186}
187
188/// RAII scope guard restoring the previous ambient `Context` on drop.
189#[derive(CustomDebug, New)]
190pub struct ContextGuard {
191 /// Previously bound ambient context to restore when leaving scope.
192 pub(crate) previous: Option<Context>,
193}