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}
76
77/// Compact direct-mapped/set-associative cache slot storing a measured text bounding box.
78#[derive(Clone, Copy, Debug, Default)]
79pub(crate) struct TextSizeEntry {
80    /// Primary 64-bit hash of the measured UTF-8 text bytes.
81    pub(crate) hash_a: u64,
82    /// Secondary independent 64-bit hash of the measured UTF-8 text bytes.
83    pub(crate) hash_b: u64,
84    /// Exact byte length of the measured text string.
85    pub(crate) text_len: u32,
86    /// Normalized IEEE-754 bits of `TextStyle::font_size`.
87    pub(crate) font_size_bits: u32,
88    /// Normalized IEEE-754 bits of `TextStyle::line_height`.
89    pub(crate) line_height_bits: u32,
90    /// Normalized IEEE-754 bits of `TextStyle::letter_spacing`.
91    pub(crate) letter_spacing_bits: u32,
92    /// Normalized IEEE-754 bits of `max_width`, or `TEXT_SIZE_MAX_WIDTH_NONE_BITS` when `None`.
93    pub(crate) max_width_bits: u32,
94    /// Cached measured bounding width in logical pixels.
95    pub(crate) width: f32,
96    /// Cached measured bounding height in logical pixels.
97    pub(crate) height: f32,
98    /// Packed typography flags (`family`, `weight`, `overflow`, `italic`, and occupied bit).
99    pub(crate) style_flags: u16,
100}
101
102/// Bounded 2-way set-associative cache mapping `(text, style, max_width)` to measured `Size`.
103#[derive(Clone, Debug, Default)]
104pub(crate) struct TextSizeCache {
105    /// Lazily allocated flat table of `TEXT_SIZE_CACHE_SLOTS` entries (`2` ways per set).
106    pub(crate) entries: Vec<TextSizeEntry>,
107}
108
109/// Compact single-cache-line scratch record tracking a flex child across probe and placement passes.
110#[derive(Clone, Copy, Debug, Default)]
111pub(crate) struct FlexItemRecord {
112    /// Scene node handle of the flex child.
113    pub(crate) node_id: NodeId,
114    /// Current target size updated by flex grow and auto-cross re-probing.
115    pub(crate) size: Size,
116    /// Border-box size produced by the initial probe pass.
117    pub(crate) probed_size: Size,
118    /// Logical origin where the child currently resides after the probe pass.
119    pub(crate) probed_origin: Point,
120    /// Outer margin insets copied once from `LayoutStyle`.
121    pub(crate) margin: Edges,
122    /// Flex grow factor copied once from `LayoutStyle`.
123    pub(crate) flex_grow: f32,
124    /// Effective `align-self` override copied once from `LayoutStyle`.
125    pub(crate) align_self: AlignSelf,
126    /// Overflow clipping behavior copied once from `LayoutStyle`.
127    pub(crate) overflow: Overflow,
128    /// Packed boolean flags (`FLEX_ITEM_*`) describing child sizing constraints and probe state.
129    pub(crate) flags: u16,
130}
131
132/// Shared axis and container parameters passed to `LayoutEngine::layout_flex_line`.
133#[derive(Clone, Copy, Debug)]
134pub(crate) struct FlexLineContext {
135    /// Enclosing flex container constraints and origin.
136    pub(crate) frame: ContainerFrame,
137    /// `true` when main axis is horizontal (`Row`/`RowReverse`).
138    pub(crate) is_row: bool,
139    /// `true` when multi-line flex wrapping is enabled.
140    pub(crate) wrap_enabled: bool,
141    /// Main-axis gap between adjacent items in logical pixels.
142    pub(crate) main_gap: f32,
143    /// Inner available main-axis extent of the container.
144    pub(crate) main_avail: f32,
145    /// Inner available cross-axis extent of the container.
146    pub(crate) cross_avail: f32,
147    /// Aggregate `flex_grow` sum across items in the container.
148    pub(crate) total_grow: f32,
149    /// Total number of flex lines in the container.
150    pub(crate) line_count: usize,
151}