Skip to main content

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}
73
74/// Shared handle wrapping a `SceneTree` so reactive `Effect` closures can patch nodes directly.
75#[derive(Clone, CustomDebug)]
76pub struct SceneHandle {
77    /// Shared interior-mutable reference to the thread-local scene tree.
78    pub(crate) inner: Rc<RefCell<SceneTree>>,
79}
80
81/// Ambient framework-managed UI context binding the active `SceneHandle`, responsive signals, and platform metadata.
82#[derive(Clone, CustomDebug, Data)]
83pub struct Context {
84    /// Shared scene tree handle for creating and binding nodes.
85    pub(crate) scene: SceneHandle,
86    /// Current viewport logical breakpoint signal for responsive layouts.
87    #[get(type(copy))]
88    pub(crate) breakpoint: Signal<Breakpoint>,
89    /// Current logical viewport dimensions signal updated immediately on window resize.
90    #[get(type(copy))]
91    pub(crate) viewport_size: Signal<Size>,
92    /// Current OS/app theme mode signal (`Light` / `Dark`).
93    #[get(type(copy))]
94    pub(crate) theme_mode: Signal<ThemeMode>,
95    /// Active platform kind for capability-aware adaptation.
96    #[get(type(copy))]
97    pub(crate) platform: PlatformKind,
98    /// Active safe-area insets signal.
99    #[get(type(copy))]
100    pub(crate) safe_area: Signal<SafeAreaInsets>,
101    /// Reactive stream of recognized cross-platform gestures (`Tap`, `DoubleTap`, `LongPress`, `Swipe*`, `Pan`, `Pinch`).
102    #[get(type(copy))]
103    pub(crate) gesture: Signal<Option<GestureEvent>>,
104    /// Live horizontal touch-swipe drag displacement in logical pixels (`0.0` when idle) for interactive page-swipe feedback.
105    #[get(type(copy))]
106    pub(crate) swipe_drag_offset: Signal<f32>,
107    /// Monotonic counter incremented on OS Back button / Escape / edge-back triggers for unified overlay & router stack dismissal.
108    #[get(type(copy))]
109    pub(crate) system_back: Signal<u64>,
110    /// Shared dynamic update hub enabling ambient component-level and page-level live updates.
111    pub(crate) dynamic_hub: DynamicUpdateHub,
112    /// Optional target FPS cap across all platforms (`None` = unlimited maximum FPS by default).
113    #[get(type(copy))]
114    pub(crate) fps_limit: Signal<Option<u32>>,
115    /// Smoothed live rendered frames-per-second telemetry signal.
116    #[get(type(copy))]
117    pub(crate) live_fps: Signal<f32>,
118    /// Idle-aware active presented frames-per-second signal (`0.0` while idle).
119    #[get(type(copy))]
120    pub(crate) present_fps: Signal<f32>,
121    /// Reactive flag indicating whether the frame loop is currently idle (`true` when skipping clean frames).
122    #[get(type(copy))]
123    pub(crate) is_idle: Signal<bool>,
124    /// Native hardware display refresh rate in Hertz reported by the active OS/browser host.
125    #[get(type(copy))]
126    pub(crate) display_refresh_rate: Signal<f32>,
127    /// Live snapshot of all currently active touch/pointer contacts `(pointer_id, position)` for multi-touch UIs.
128    #[get(type(copy))]
129    pub(crate) active_touches: Signal<Vec<(u64, Point)>>,
130    /// Reactive flag raised when the application requests graceful termination (e.g. double-back-to-exit at root).
131    #[get(type(copy))]
132    pub(crate) exit_requested: Signal<bool>,
133    /// Canonical cross-platform application lifecycle state signal (`Active`, `Inactive`, `Background`, `Terminated`).
134    #[get(type(copy))]
135    pub(crate) app_state: Signal<AppState>,
136    /// Live network reachability status signal (`Online`, `Offline`, `Wifi`, `Cellular`, `Unknown`).
137    #[get(type(copy))]
138    pub(crate) network_status: Signal<NetworkStatus>,
139    /// Whether the soft virtual keyboard / IME is currently presented.
140    #[get(type(copy))]
141    pub(crate) keyboard_visible: Signal<bool>,
142    /// Current soft virtual keyboard height in logical pixels (`0.0` when hidden).
143    #[get(type(copy))]
144    pub(crate) keyboard_height: Signal<f32>,
145    /// Current screen or window orientation signal.
146    #[get(type(copy))]
147    pub(crate) orientation: Signal<ScreenOrientation>,
148    /// Whether OS battery saver / low-power mode is currently enabled.
149    #[get(type(copy))]
150    pub(crate) low_power_mode: Signal<bool>,
151    /// Active OS/browser preferred BCP-47 locale string signal.
152    #[get(type(copy))]
153    pub(crate) locale: Signal<String>,
154    /// Whether the primary application window currently holds keyboard/input focus.
155    #[get(type(copy))]
156    pub(crate) window_focused: Signal<bool>,
157    /// Reactive flag indicating whether immersive fullscreen mode is active across app chrome and OS system bars.
158    #[get(type(copy))]
159    #[set(skip)]
160    pub(crate) immersive_fullscreen: Signal<bool>,
161    /// Nested immersive fullscreen entry counter enabling balanced RAII enter/exit calls.
162    #[debug(skip)]
163    #[get(skip)]
164    #[get_mut(skip)]
165    #[set(skip)]
166    pub(crate) fullscreen_depth: Rc<Cell<u32>>,
167    /// Monotonic runtime clock in milliseconds advanced deterministically by `App` frame steps.
168    #[debug(skip)]
169    #[get(skip)]
170    pub(crate) clock_ms: Rc<Cell<u64>>,
171}
172
173/// RAII scope guard restoring the previous ambient `Context` on drop.
174#[derive(CustomDebug, New)]
175pub struct ContextGuard {
176    /// Previously bound ambient context to restore when leaving scope.
177    pub(crate) previous: Option<Context>,
178}