Layout algorithm decoupling, Sizing Constraints & Perf Improvements (#246)
1//! Node Data - important layout and styling data for nodes
2//!
3//! Used to compute layout for Taffy trees
4//!
5use crate::layout::{Cache, Layout};
6use crate::style::FlexboxLayout;
7
8/// Layout information for a given [`Node`](crate::node::Node)
9///
10/// Stored in a [`Taffy`].
11pub(crate) struct NodeData {
12 /// The layout strategy used by this node
13 pub(crate) style: FlexboxLayout,
14 /// The results of the layout computation
15 pub(crate) layout: Layout,
16
17 /// Should we try and measure this node?
18 pub(crate) needs_measure: bool,
19
20 /// The primary cached results of the layout computation
21 pub(crate) size_cache: [Option<Cache>; 4],
22 /// Does this node's layout need to be recomputed?
23 pub(crate) is_dirty: bool,
24}
25
26impl NodeData {
27 /// Create the data for a new node
28 #[must_use]
29 pub const fn new(style: FlexboxLayout) -> Self {
30 Self { style, size_cache: [None; 4], layout: Layout::new(), is_dirty: true, needs_measure: false }
31 }
32
33 /// Marks a node and all of its parents (recursively) as dirty
34 ///
35 /// This clears any cached data and signals that the data must be recomputed.
36 #[inline]
37 pub fn mark_dirty(&mut self) {
38 self.size_cache = [None; 4];
39 self.is_dirty = true;
40 }
41}