Skip to main content

euv_core/layout/engine/
struct.rs

1use super::*;
2
3/// Deterministic cross-platform Flexbox, Grid, Block, and Positioned layout engine.
4#[derive(Clone, Data, Debug, Default)]
5pub struct LayoutEngine {
6    /// Deterministic text measurer shared with the rendering pass.
7    #[get(type(copy))]
8    pub(crate) measurer: DeterministicTextMeasurer,
9    /// Statistics captured from the most recent layout pass.
10    #[get(type(copy))]
11    pub(crate) last_stats: LayoutStats,
12    /// Reusable flat stack storing copied child handles across recursive `layout_node` frames.
13    #[get(pub(crate))]
14    #[get_mut(pub(crate))]
15    #[set(skip)]
16    pub(crate) children_scratch: Vec<NodeId>,
17    /// Reusable flat stack storing normal-flow child handles across recursive `layout_children` frames.
18    #[get(pub(crate))]
19    #[get_mut(pub(crate))]
20    #[set(skip)]
21    pub(crate) flow_scratch: Vec<NodeId>,
22    /// Reusable flat stack storing absolute/fixed overlay child handles across recursive `layout_children` frames.
23    #[get(pub(crate))]
24    #[get_mut(pub(crate))]
25    #[set(skip)]
26    pub(crate) abs_scratch: Vec<NodeId>,
27    /// Reusable flat stack storing measured flex child records across recursive `layout_flex` frames.
28    #[get(pub(crate))]
29    #[get_mut(pub(crate))]
30    #[set(skip)]
31    pub(crate) flex_items_scratch: Vec<FlexItemRecord>,
32    /// Reusable flat stack storing contiguous `(start, end)` line slices into `flex_items_scratch`.
33    #[get(pub(crate))]
34    #[get_mut(pub(crate))]
35    #[set(skip)]
36    pub(crate) flex_lines_scratch: Vec<(usize, usize)>,
37    /// Reusable stack buffer for iterative zero-allocation subtree translations.
38    #[get(skip)]
39    #[get_mut(pub(crate))]
40    #[set(skip)]
41    pub(crate) translate_scratch: Vec<NodeId>,
42    /// Bounded 2-way set-associative cache of measured text sizes for layout passes.
43    #[get(skip)]
44    #[get_mut(pub(crate))]
45    #[set(skip)]
46    pub(crate) text_size_cache: TextSizeCache,
47    /// Whether the active layout pass is recording pre-layout geometry snapshots for partial damage diffing.
48    #[get(skip)]
49    #[get_mut(skip)]
50    #[set(skip)]
51    pub(crate) track_damage: bool,
52    /// Active fallback trigger recorded during a tracked layout pass (`LAYOUT_FALLBACK_*`).
53    #[get(skip)]
54    #[get_mut(skip)]
55    #[set(skip)]
56    pub(crate) damage_fallback: u8,
57    /// Bounded pre-layout geometry snapshots collected during surgical partial-layout damage diffing.
58    #[get(skip)]
59    #[get_mut(skip)]
60    #[set(skip)]
61    pub(crate) layout_snapshots: Vec<LayoutNodeSnapshot>,
62}
63
64/// Pre-layout geometry snapshot used for surgical partial-layout damage diffing.
65#[derive(Clone, Copy, Debug, Default, PartialEq)]
66pub(crate) struct LayoutNodeSnapshot {
67    /// Target scene node handle.
68    pub(crate) id: NodeId,
69    /// Pre-layout border-box rectangle in layout coordinates.
70    pub(crate) old_bounds: Rect,
71    /// Pre-layout content-box rectangle in layout coordinates.
72    pub(crate) old_content_bounds: Rect,
73    /// Pre-layout intrinsic content dimensions.
74    pub(crate) old_content_size: Size,
75    /// Whether `old_screen` holds a valid pre-layout conservative logical screen rectangle.
76    pub(crate) has_old_screen: bool,
77    /// Pre-layout conservative logical screen bounds (including shadow, border, scroll, and transform).
78    pub(crate) old_screen: Rect,
79}
80
81/// Outcome of surgical pre/post-layout conservative bounds diffing.
82#[derive(Clone, Copy, Debug, Default, PartialEq)]
83pub(crate) struct LayoutDamageReport {
84    /// Tight physical damage rectangles unioning old and new bounds of geometry-changed nodes.
85    pub(crate) damage: DamageRegion,
86    /// Fallback trigger (`LAYOUT_FALLBACK_*`) requesting full-viewport damage when non-zero.
87    pub(crate) fallback_kind: u8,
88}