euv-core 0.48.0

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Computed layout geometry cached on every scene node.
#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
pub struct LayoutBox {
    /// Absolute border-box bounds in root logical coordinates.
    #[get(type(copy))]
    pub(crate) bounds: Rect,
    /// Inner content-box bounds inside padding and border.
    #[get(type(copy))]
    pub(crate) content_bounds: Rect,
    /// Intrinsic scrollable content size.
    #[get(type(copy))]
    pub(crate) content_size: Size,
    /// Active scroll offset inside scroll containers.
    #[get(type(copy))]
    pub(crate) scroll_offset: Point,
}

/// Interactive visual state flags on a scene node.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
pub struct InteractionState {
    /// Whether the node can receive keyboard focus.
    #[get(type(copy))]
    pub(crate) focusable: bool,
    /// Whether the node currently holds keyboard focus.
    #[get(type(copy))]
    pub(crate) focused: bool,
    /// Whether a pointer currently hovers over this node.
    #[get(type(copy))]
    pub(crate) hovered: bool,
    /// Whether a pointer is actively pressed on this node.
    #[get(type(copy))]
    pub(crate) pressed: bool,
}

/// Theme-origin paint snapshot recorded the first time a node is restyled by an in-place theme remap.
///
/// Remapping always resolves from this origin snapshot (single hop) instead of chaining heuristic
/// value matches across successive themes, so multi-hop theme switches never drift and round trips
/// restore the exact original paint.
#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
pub struct ThemeBaseline {
    /// Opaque 16-bit theme identifier (UI layer lookup index) the snapshot was captured under.
    #[get(type(copy))]
    pub(crate) origin_key: u16,
    /// Paint (background, gradient, border, radii, shadow, focus ring) captured under the origin theme.
    #[get(type(copy))]
    pub(crate) paint: PaintStyle,
    /// Text color captured under the origin theme.
    #[get(type(copy))]
    pub(crate) text_color: Color,
    /// Effective ancestor-composited background behind this node under the origin theme.
    #[get(type(copy))]
    pub(crate) origin_eff_bg: Color,
    /// Optional hover paint override captured under the origin theme.
    #[get(type(copy))]
    pub(crate) hover: Option<PaintStyle>,
}

/// Generation-guarded per-slot theme bookkeeping stored sparsely on `SceneTree`.
#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
pub(crate) struct ThemeNodeEntry {
    /// Node generation the entry belongs to (stale entries are ignored and overwritten).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) generation: u32,
    /// Whether a component reactively owns this node's themed paint (generic remaps skip it).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) owned: bool,
    /// Theme-origin paint snapshot used by in-place remaps.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) baseline: Option<ThemeBaseline>,
}

/// Lazily allocated cold optional metadata boxed out of `SceneNode` to keep the hot node arena compact.
#[derive(CustomDebug, Data, Default)]
pub(crate) struct NodeExtras {
    /// Optional hover paint override for zero-layout-cost hover feedback.
    #[get(skip)]
    pub(crate) hover_style: Option<PaintStyle>,
    /// Optional reconciliation key for keyed list items.
    #[get(skip)]
    pub(crate) key: Option<String>,
    /// Event callbacks attached to this node.
    pub(crate) handlers: EventHandlers,
    /// Optional reactive ownership scope disposed when this node is removed.
    #[get(skip)]
    pub(crate) scope: Option<Scope>,
    /// Optional custom 2D canvas draw callback.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) canvas_painter: Option<CanvasDrawCallback>,
    /// Optional explicit semantic accessibility metadata for screen readers and ARIA bridges.
    #[get(skip)]
    pub(crate) a11y: Option<A11yProps>,
    /// Optional virtualized scroll metrics `(scroll_y, total_content_height)` for overlay scrollbar thumb accuracy.
    #[get(skip)]
    pub(crate) virtual_scroll: Option<(f32, f32)>,
    /// Registered `Lifecycle` observers receiving mount, activate, freeze, resume, unmount, and destroy hooks.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) lifecycles: Vec<Rc<dyn Lifecycle>>,
}

/// Dense 8-byte SoA per-node metadata entry stored contiguously in `SceneTree` (8 nodes per 64B cache line).
#[derive(Clone, Copy, Data, Debug, Default, Eq, New, PartialEq)]
pub(crate) struct NodeMeta {
    /// Generation tag matching live `NodeId` handles.
    #[get(pub(crate), type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) generation: u32,
    /// Per-node structural bitflags (`NODE_FLAG_*`).
    #[get(pub(crate), type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) flags: u16,
    /// Surgical dirty bitmask mirrored in SoA for cache-dense traversal.
    #[get(pub(crate), type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) dirty: u16,
}

/// Dense 24-byte SoA intrusive doubly-linked tree topology entry eliminating per-container `Vec<NodeId>` heap allocations.
#[derive(Clone, Copy, Data, Debug, Eq, PartialEq)]
pub(crate) struct NodeTopology {
    /// Parent slot index (`NODE_INDEX_NONE` when detached or root).
    #[get(pub(crate), type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) parent: u32,
    /// First direct child slot index (`NODE_INDEX_NONE` when leaf).
    #[get(pub(crate), type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) first_child: u32,
    /// Last direct child slot index (`NODE_INDEX_NONE` when leaf) enabling O(1) append and reverse iteration.
    #[get(pub(crate), type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) last_child: u32,
    /// Next sibling slot index (`NODE_INDEX_NONE` at tail).
    #[get(pub(crate), type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) next_sibling: u32,
    /// Previous sibling slot index (`NODE_INDEX_NONE` at head).
    #[get(pub(crate), type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) prev_sibling: u32,
    /// Cached direct child count for O(1) `child_count` and `has_children` queries.
    #[get(pub(crate), type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) child_count: u32,
}

/// Retained scene node stored contiguously inside `SceneTree`.
#[derive(CustomDebug, Data)]
pub struct SceneNode {
    /// Generation tag matching live `NodeId` handles.
    #[get(type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) generation: u32,
    /// Whether this arena slot is currently occupied.
    #[get(type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) alive: bool,
    /// Compact structural flags (`NODE_FLAG_ALIVE`, `NODE_FLAG_HAS_EXTRAS`, `NODE_FLAG_HAS_LIFECYCLE`, `NODE_FLAG_HAS_SCOPE`).
    #[get(type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) node_flags: u16,
    /// Semantic kind and node-specific payload.
    pub(crate) kind: NodeKind,
    /// Compiled layout, paint, and typography style.
    #[get(type(copy))]
    pub(crate) style: Style,
    /// Computed layout box and scroll offsets.
    #[get(type(copy))]
    pub(crate) layout_box: LayoutBox,
    /// Cached previous layout constraints for clean-subtree O(1) skipping.
    #[get(skip)]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) last_constraint: Option<AvailableSpace>,
    /// Surgical dirty bitmask.
    #[get(type(copy))]
    pub(crate) dirty: DirtyFlags,
    /// Parent node handle if attached to the tree.
    #[get(skip)]
    pub(crate) parent: Option<NodeId>,
    /// Interactive focus/hover/pressed state.
    #[get(type(copy))]
    pub(crate) interaction: InteractionState,
    /// Lazily boxed cold optional metadata (handlers, hover style, a11y, lifecycles, scope, canvas, key, virtual scroll).
    #[debug(skip)]
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) extras: Option<Box<NodeExtras>>,
}