Skip to main content

euv_core/layout/cache/
struct.rs

1use super::*;
2
3/// Available layout space passed down during a layout pass and cached for clean-subtree skipping.
4#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
5pub struct AvailableSpace {
6    /// Available horizontal extent in logical pixels.
7    #[get(type(copy))]
8    pub(crate) width: f32,
9    /// Available vertical extent in logical pixels.
10    #[get(type(copy))]
11    pub(crate) height: f32,
12    /// Root viewport size for `vw`/`vh` length resolution.
13    #[get(type(copy))]
14    pub(crate) viewport: Size,
15    /// Origin X coordinate where this node is placed.
16    #[get(type(copy))]
17    pub(crate) origin_x: f32,
18    /// Origin Y coordinate where this node is placed.
19    #[get(type(copy))]
20    pub(crate) origin_y: f32,
21    /// Whether the parent stretched this node's width to fill `width` when its declared width is `Length::Auto`.
22    #[get(type(copy))]
23    #[new(skip)]
24    pub(crate) stretch_width: bool,
25    /// Whether the parent stretched this node's height to fill `height` when its declared height is `Length::Auto`.
26    #[get(type(copy))]
27    #[new(skip)]
28    pub(crate) stretch_height: bool,
29}
30
31/// Internal container constraint bundle passed to child layout solvers.
32#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
33pub(crate) struct ContainerFrame {
34    /// Parent layout properties.
35    #[get(pub(crate), type(copy))]
36    #[get_mut(pub(crate))]
37    #[set(pub(crate))]
38    pub(crate) parent_layout: LayoutStyle,
39    /// Inner available dimensions inside padding and border.
40    #[get(pub(crate), type(copy))]
41    #[get_mut(pub(crate))]
42    #[set(pub(crate))]
43    pub(crate) inner_avail: Size,
44    /// Root viewport logical size.
45    #[get(pub(crate), type(copy))]
46    #[get_mut(pub(crate))]
47    #[set(pub(crate))]
48    pub(crate) viewport: Size,
49    /// Content origin in root coordinates.
50    #[get(pub(crate), type(copy))]
51    #[get_mut(pub(crate))]
52    #[set(pub(crate))]
53    pub(crate) content_origin: Point,
54    /// Whether the container's outer width is definite (explicit length, aspect ratio, or parent stretch).
55    #[get(pub(crate), type(copy))]
56    #[get_mut(pub(crate))]
57    #[set(pub(crate))]
58    pub(crate) definite_width: bool,
59    /// Whether the container's outer height is definite (explicit length, aspect ratio, or parent stretch).
60    #[get(pub(crate), type(copy))]
61    #[get_mut(pub(crate))]
62    #[set(pub(crate))]
63    pub(crate) definite_height: bool,
64}
65
66/// Telemetry counters recorded per layout pass.
67#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, Ord, PartialEq, PartialOrd)]
68pub struct LayoutStats {
69    /// Number of nodes laid out during this pass.
70    #[get(type(copy))]
71    pub(crate) nodes_computed: usize,
72    /// Number of clean subtrees skipped in O(1) via constraint caching.
73    #[get(type(copy))]
74    pub(crate) subtrees_skipped: usize,
75    /// Number of nodes whose final layout geometry actually changed during this pass.
76    #[get(type(copy))]
77    #[new(skip)]
78    pub(crate) nodes_changed: usize,
79}
80
81/// Cumulative layout invalidation and effectiveness telemetry separating runs from actual geometric mutations.
82#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
83pub struct LayoutTelemetry {
84    /// Cumulative layout-invalidating scene mutations (`layout.invalidations`).
85    #[get(type(copy))]
86    pub(crate) invalidations: u64,
87    /// Cumulative executed layout passes (`layout.passes`).
88    #[get(type(copy))]
89    pub(crate) passes: u64,
90    /// Cumulative layout passes that produced at least one geometric change (`layout.changed_passes`).
91    #[get(type(copy))]
92    pub(crate) changed_passes: u64,
93    /// Cumulative count of nodes whose layout box actually changed (`layout.changed_nodes_total`).
94    #[get(type(copy))]
95    pub(crate) changed_nodes_total: u64,
96}
97
98/// Compact direct-mapped/set-associative cache slot storing a measured text bounding box.
99#[derive(Clone, Copy, Debug, Default)]
100pub(crate) struct TextSizeEntry {
101    /// Primary 64-bit hash of the measured UTF-8 text bytes.
102    pub(crate) hash_a: u64,
103    /// Secondary independent 64-bit hash of the measured UTF-8 text bytes.
104    pub(crate) hash_b: u64,
105    /// Exact byte length of the measured text string.
106    pub(crate) text_len: u32,
107    /// Normalized IEEE-754 bits of `TextStyle::font_size`.
108    pub(crate) font_size_bits: u32,
109    /// Normalized IEEE-754 bits of `TextStyle::line_height`.
110    pub(crate) line_height_bits: u32,
111    /// Normalized IEEE-754 bits of `TextStyle::letter_spacing`.
112    pub(crate) letter_spacing_bits: u32,
113    /// Normalized IEEE-754 bits of `max_width`, or `TEXT_SIZE_MAX_WIDTH_NONE_BITS` when `None`.
114    pub(crate) max_width_bits: u32,
115    /// Cached measured bounding width in logical pixels.
116    pub(crate) width: f32,
117    /// Cached measured bounding height in logical pixels.
118    pub(crate) height: f32,
119    /// Packed typography flags (`family`, `weight`, `overflow`, `italic`, and occupied bit).
120    pub(crate) style_flags: u16,
121}
122
123/// Bounded 2-way set-associative cache mapping `(text, style, max_width)` to measured `Size`.
124#[derive(Clone, Debug, Default)]
125pub(crate) struct TextSizeCache {
126    /// Lazily allocated flat table of `TEXT_SIZE_CACHE_SLOTS` entries (`2` ways per set).
127    pub(crate) entries: Vec<TextSizeEntry>,
128}
129
130/// Compact single-cache-line scratch record tracking a flex child across probe and placement passes.
131#[derive(Clone, Copy, Debug, Default)]
132pub(crate) struct FlexItemRecord {
133    /// Scene node handle of the flex child.
134    pub(crate) node_id: NodeId,
135    /// Current target size updated by flex grow and auto-cross re-probing.
136    pub(crate) size: Size,
137    /// Border-box size produced by the initial probe pass.
138    pub(crate) probed_size: Size,
139    /// Logical origin where the child currently resides after the probe pass.
140    pub(crate) probed_origin: Point,
141    /// Outer margin insets copied once from `LayoutStyle`.
142    pub(crate) margin: Edges,
143    /// Flex grow factor copied once from `LayoutStyle`.
144    pub(crate) flex_grow: f32,
145    /// Effective `align-self` override copied once from `LayoutStyle`.
146    pub(crate) align_self: AlignSelf,
147    /// Overflow clipping behavior copied once from `LayoutStyle`.
148    pub(crate) overflow: Overflow,
149    /// Packed boolean flags (`FLEX_ITEM_*`) describing child sizing constraints and probe state.
150    pub(crate) flags: u16,
151}
152
153/// Shared axis and container parameters passed to `LayoutEngine::layout_flex_line`.
154#[derive(Clone, Copy, Debug)]
155pub(crate) struct FlexLineContext {
156    /// Enclosing flex container constraints and origin.
157    pub(crate) frame: ContainerFrame,
158    /// `true` when main axis is horizontal (`Row`/`RowReverse`).
159    pub(crate) is_row: bool,
160    /// `true` when multi-line flex wrapping is enabled.
161    pub(crate) wrap_enabled: bool,
162    /// Main-axis gap between adjacent items in logical pixels.
163    pub(crate) main_gap: f32,
164    /// Inner available main-axis extent of the container.
165    pub(crate) main_avail: f32,
166    /// Inner available cross-axis extent of the container.
167    pub(crate) cross_avail: f32,
168    /// Aggregate `flex_grow` sum across items in the container.
169    pub(crate) total_grow: f32,
170    /// Total number of flex lines in the container.
171    pub(crate) line_count: usize,
172}