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    /// Root scene node handle.
14    #[get(type(copy))]
15    pub(crate) root: NodeId,
16    /// Focus, hover, and pointer-press tracking state.
17    #[get(type(copy))]
18    pub(crate) focus: FocusManager,
19    /// Monotonic structural/visual mutation counter.
20    #[get(type(copy))]
21    pub(crate) revision: u64,
22    /// Active paint/transform node transitions ticked on every frame until settled.
23    pub(crate) transitions: Vec<NodeTransition>,
24    /// Blinking visibility state of the focused text input caret (`true` = visible phase).
25    #[get(type(copy))]
26    pub(crate) caret_visible: bool,
27}
28
29/// Shared handle wrapping a `SceneTree` so reactive `Effect` closures can patch nodes directly.
30#[derive(Clone, CustomDebug)]
31pub struct SceneHandle {
32    /// Shared interior-mutable reference to the thread-local scene tree.
33    pub(crate) inner: Rc<RefCell<SceneTree>>,
34}
35
36/// Ambient framework-managed UI context binding the active `SceneHandle`, responsive signals, and platform metadata.
37#[derive(Clone, CustomDebug, Data)]
38pub struct Context {
39    /// Shared scene tree handle for creating and binding nodes.
40    pub(crate) scene: SceneHandle,
41    /// Current viewport logical breakpoint signal for responsive layouts.
42    #[get(type(copy))]
43    pub(crate) breakpoint: Signal<Breakpoint>,
44    /// Current logical viewport dimensions signal updated immediately on window resize.
45    #[get(type(copy))]
46    pub(crate) viewport_size: Signal<Size>,
47    /// Current OS/app theme mode signal (`Light` / `Dark`).
48    #[get(type(copy))]
49    pub(crate) theme_mode: Signal<ThemeMode>,
50    /// Active platform kind for capability-aware adaptation.
51    #[get(type(copy))]
52    pub(crate) platform: PlatformKind,
53    /// Active safe-area insets signal.
54    #[get(type(copy))]
55    pub(crate) safe_area: Signal<SafeAreaInsets>,
56    /// Reactive stream of recognized cross-platform gestures (`Tap`, `DoubleTap`, `LongPress`, `Swipe*`, `Pan`, `Pinch`).
57    #[get(type(copy))]
58    pub(crate) gesture: Signal<Option<GestureEvent>>,
59    /// Monotonic counter incremented on OS Back button / Escape / edge-back triggers for unified overlay & router stack dismissal.
60    #[get(type(copy))]
61    pub(crate) system_back: Signal<u64>,
62    /// Shared dynamic update hub enabling ambient component-level and page-level live updates.
63    pub(crate) dynamic_hub: DynamicUpdateHub,
64    /// Optional target FPS cap across all platforms (`None` = unlimited maximum FPS by default).
65    #[get(type(copy))]
66    pub(crate) fps_limit: Signal<Option<u32>>,
67    /// Smoothed live rendered frames-per-second telemetry signal.
68    #[get(type(copy))]
69    pub(crate) live_fps: Signal<f32>,
70    /// Live snapshot of all currently active touch/pointer contacts `(pointer_id, position)` for multi-touch UIs.
71    #[get(type(copy))]
72    pub(crate) active_touches: Signal<Vec<(u64, Point)>>,
73    /// Reactive flag raised when the application requests graceful termination (e.g. double-back-to-exit at root).
74    #[get(type(copy))]
75    pub(crate) exit_requested: Signal<bool>,
76    /// Monotonic runtime clock in milliseconds advanced deterministically by `App` frame steps.
77    #[debug(skip)]
78    #[get(skip)]
79    pub(crate) clock_ms: Rc<Cell<u64>>,
80}
81
82/// RAII scope guard restoring the previous ambient `Context` on drop.
83#[derive(CustomDebug, New)]
84pub struct ContextGuard {
85    /// Previously bound ambient context to restore when leaving scope.
86    pub(crate) previous: Option<Context>,
87}