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::Style;
7
8/// The number of cache entries for each node in the tree
9pub(crate) const CACHE_SIZE: usize = 7;
10
11/// Layout information for a given [`Node`](crate::node::Node)
12///
13/// Stored in a [`Taffy`].
14pub(crate) struct NodeData {
15 /// The layout strategy used by this node
16 pub(crate) style: Style,
17 /// The results of the layout computation
18 pub(crate) layout: Layout,
19
20 /// Should we try and measure this node?
21 pub(crate) needs_measure: bool,
22
23 /// The primary cached results of the layout computation
24 pub(crate) size_cache: [Option<Cache>; CACHE_SIZE],
25}
26
27impl NodeData {
28 /// Create the data for a new node
29 #[must_use]
30 pub const fn new(style: Style) -> Self {
31 Self { style, size_cache: [None; CACHE_SIZE], layout: Layout::new(), needs_measure: false }
32 }
33
34 /// Marks a node and all of its parents (recursively) as dirty
35 ///
36 /// This clears any cached data and signals that the data must be recomputed.
37 #[inline]
38 pub fn mark_dirty(&mut self) {
39 self.size_cache = [None; CACHE_SIZE];
40 }
41}