tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1116HTML 1041Markdown 12TOML 94780 Definitions

⎇ 3bda6444237f92c60a8a9ba24495554b9faa72c3 src/data.rs Rust · 39 lines · 1.1 KB History Who touched what raw

Move cache logic to own module (#432) 3bda64442 · Nico Burns ·

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