tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Sutichaykuna

⎇ 9118437ed51cb90c74f2880c9c2b728e8b0c890d src/data.rs Rust · 51 siq'ikuna · 1.5 KB Ñawpa willay Pi imata llamkarqan ch'uya

Abstract flexbox over LayoutTree (rebased on top of latest main) (#238) 9118437ed · 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::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) main_size_layout_cache: Option<Cache>,
22    /// Secondary cached results of the layout computation
23    pub(crate) other_layout_cache: Option<Cache>,
24    /// Does this node's layout need to be recomputed?
25    pub(crate) is_dirty: bool,
26}
27
28impl NodeData {
29    /// Create the data for a new node
30    #[must_use]
31    pub const fn new(style: FlexboxLayout) -> Self {
32        Self {
33            style,
34            main_size_layout_cache: None,
35            other_layout_cache: None,
36            layout: Layout::new(),
37            is_dirty: true,
38            needs_measure: false,
39        }
40    }
41
42    /// Marks a node and all of its parents (recursively) as dirty
43    ///
44    /// This clears any cached data and signals that the data must be recomputed.
45    #[inline]
46    pub fn mark_dirty(&mut self) {
47        self.main_size_layout_cache = None;
48        self.other_layout_cache = None;
49        self.is_dirty = true;
50    }
51}