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::*;

/// Deterministic cross-platform Flexbox, Grid, Block, and Positioned layout engine.
#[derive(Clone, Data, Debug, Default)]
pub struct LayoutEngine {
    /// Deterministic text measurer shared with the rendering pass.
    #[get(type(copy))]
    pub(crate) measurer: DeterministicTextMeasurer,
    /// Statistics captured from the most recent layout pass.
    #[get(type(copy))]
    pub(crate) last_stats: LayoutStats,
    /// Cumulative layout invalidation, pass, and changed-node telemetry counters.
    #[get(type(copy))]
    pub(crate) telemetry: LayoutTelemetry,
    /// Reusable flat stack storing copied child handles across recursive `layout_node` frames.
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(skip)]
    pub(crate) children_scratch: Vec<NodeId>,
    /// Reusable flat stack storing normal-flow child handles across recursive `layout_children` frames.
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(skip)]
    pub(crate) flow_scratch: Vec<NodeId>,
    /// Reusable flat stack storing absolute/fixed overlay child handles across recursive `layout_children` frames.
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(skip)]
    pub(crate) abs_scratch: Vec<NodeId>,
    /// Reusable flat stack storing measured flex child records across recursive `layout_flex` frames.
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(skip)]
    pub(crate) flex_items_scratch: Vec<FlexItemRecord>,
    /// Reusable flat stack storing contiguous `(start, end)` line slices into `flex_items_scratch`.
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(skip)]
    pub(crate) flex_lines_scratch: Vec<(usize, usize)>,
    /// Reusable stack buffer for iterative zero-allocation subtree translations.
    #[get(skip)]
    #[get_mut(pub(crate))]
    #[set(skip)]
    pub(crate) translate_scratch: Vec<NodeId>,
    /// Bounded 2-way set-associative interval-aware cache of measured text sizes for layout passes.
    #[get(skip)]
    #[get_mut(pub(crate))]
    #[set(skip)]
    pub(crate) text_size_cache: TextSizeCache,
    /// Whether the active layout pass is recording pre-layout geometry snapshots for partial damage diffing.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) track_damage: bool,
    /// Active fallback trigger recorded during a tracked layout pass (`LAYOUT_FALLBACK_*`).
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) damage_fallback: u8,
    /// Bounded pre-layout geometry snapshots collected during surgical partial-layout damage diffing.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) layout_snapshots: Vec<LayoutNodeSnapshot>,
    /// Flat SoA split measure/final layout cache, spatial subtree bounds, and generation-stamped dedup state.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) split_cache: SplitLayoutCache,
    /// Split cache and interval text cache diagnostics from the most recent layout pass.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) last_split_stats: SplitCacheStats,
}

/// Pre-layout geometry snapshot used for surgical partial-layout damage diffing.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub(crate) struct LayoutNodeSnapshot {
    /// Target scene node handle.
    pub(crate) id: NodeId,
    /// Pre-layout border-box rectangle in layout coordinates.
    pub(crate) old_bounds: Rect,
    /// Pre-layout content-box rectangle in layout coordinates.
    pub(crate) old_content_bounds: Rect,
    /// Pre-layout intrinsic content dimensions.
    pub(crate) old_content_size: Size,
    /// Whether `old_screen` holds a valid pre-layout conservative logical screen rectangle.
    pub(crate) has_old_screen: bool,
    /// Pre-layout conservative logical screen bounds (including shadow, border, scroll, and transform).
    pub(crate) old_screen: Rect,
}

/// Outcome of surgical pre/post-layout conservative bounds diffing.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub(crate) struct LayoutDamageReport {
    /// Tight physical damage rectangles unioning old and new bounds of geometry-changed nodes.
    pub(crate) damage: DamageRegion,
    /// Fallback trigger (`LAYOUT_FALLBACK_*`) requesting full-viewport damage when non-zero.
    pub(crate) fallback_kind: u8,
}

/// Immutable hit-test query context passed across recursive spatial traversal frames.
#[derive(Clone, Copy)]
pub(crate) struct HitTestQuery<'a> {
    /// Retained scene tree being hit-tested.
    pub(crate) tree: &'a SceneTree,
    /// Target logical pointer coordinates in root space.
    pub(crate) point: Point,
    /// Whether traversal is already inside the top-layer portal pass.
    pub(crate) in_portal_pass: bool,
    /// Optional synced spatial layout cache providing `subtree_bounds` and `has_nonzero_z_child`.
    pub(crate) active_cache: Option<&'a SplitLayoutCache>,
}

/// Compact z-order sort record for zero-allocation multi-child hit testing.
#[derive(Clone, Copy, Debug, Default)]
pub(crate) struct ZItem {
    /// Child `LayoutStyle::z_index`.
    pub(crate) z_index: i32,
    /// Original child paint order index breaking z-index ties deterministically.
    pub(crate) order: usize,
    /// Child scene node handle.
    pub(crate) node_id: NodeId,
}

/// Compact sort record for zero-allocation top-layer portal hit testing.
#[derive(Clone, Copy, Debug, Default)]
pub(crate) struct PortalZItem {
    /// Portal `LayoutStyle::z_index`.
    pub(crate) z_index: i32,
    /// Top-layer portal or `Position::Fixed` node handle.
    pub(crate) node_id: NodeId,
}

/// Thread-local reusable overflow scratch buffers used by `hit_test` only above stack thresholds.
#[derive(Debug, Default)]
pub(crate) struct HitTestScratch {
    /// Flat stack of z-sorted child records when a container exceeds `HIT_TEST_STACK_Z_CAP`.
    pub(crate) z_items: Vec<ZItem>,
    /// Reusable buffer of active top-layer portals when exceeding `HIT_TEST_STACK_PORTAL_CAP`.
    pub(crate) portals: Vec<PortalZItem>,
    /// Reusable ancestor path buffer A for `tree_order_pair` when depth exceeds `HIT_TEST_STACK_PATH_CAP`.
    pub(crate) path_a: Vec<NodeId>,
    /// Reusable ancestor path buffer B for `tree_order_pair` when depth exceeds `HIT_TEST_STACK_PATH_CAP`.
    pub(crate) path_b: Vec<NodeId>,
}