tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definitions

⎇ dfaec22a1b31ebce5f35169e9af99807bb93a1b4 src/data.rs Rust · 38 lines · 1.1 KB History Who touched what raw

Change signature of mark_dirty method to match taffy 0.1 (#253) dfaec22a1 · Nico Burns ·

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/// 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: Style,
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}
23
24impl NodeData {
25    /// Create the data for a new node
26    #[must_use]
27    pub const fn new(style: Style) -> Self {
28        Self { style, size_cache: [None; 4], layout: Layout::new(), needs_measure: false }
29    }
30
31    /// Marks a node and all of its parents (recursively) as dirty
32    ///
33    /// This clears any cached data and signals that the data must be recomputed.
34    #[inline]
35    pub fn mark_dirty(&mut self) {
36        self.size_cache = [None; 4];
37    }
38}