Change signature of mark_dirty method to match taffy 0.1 (#253)
* Change signature of mark_dirty method to match taffy 0.1
* cargo fmt
dfaec22a1b31ebce5f35169e9af99807bb93a1b4 · por Nico Burns · (hace 3 años) · padre 07a154db4 · ver el árbol en este commit
diff --git a/src/compute/mod.rs b/src/compute/mod.rs
index 216fe1b86..dc1a0d9e7 100644
--- a/src/compute/mod.rs
+++ b/src/compute/mod.rs
@@ -42,9 +42,6 @@ fn compute_node_layout(
run_mode: RunMode,
sizing_mode: SizingMode,
) -> Size<f32> {
- // clear the dirtiness of the node now that we've computed it
- tree.mark_dirty(node, false);
-
#[cfg(feature = "debug")]
NODE_LOGGER.push_node(node);
#[cfg(feature = "debug")]
diff --git a/src/data.rs b/src/data.rs
index c21b09760..871bb5e73 100644
--- a/src/data.rs
+++ b/src/data.rs
@@ -19,15 +19,13 @@ pub(crate) struct NodeData {
/// The primary cached results of the layout computation
pub(crate) size_cache: [Option<Cache>; 4],
- /// Does this node's layout need to be recomputed?
- pub(crate) is_dirty: bool,
}
impl NodeData {
/// Create the data for a new node
#[must_use]
pub const fn new(style: Style) -> Self {
- Self { style, size_cache: [None; 4], layout: Layout::new(), is_dirty: true, needs_measure: false }
+ Self { style, size_cache: [None; 4], layout: Layout::new(), needs_measure: false }
}
/// Marks a node and all of its parents (recursively) as dirty
@@ -36,6 +34,5 @@ impl NodeData {
#[inline]
pub fn mark_dirty(&mut self) {
self.size_cache = [None; 4];
- self.is_dirty = true;
}
}
diff --git a/src/node.rs b/src/node.rs
index 9294cf066..9ad53f588 100644
--- a/src/node.rs
+++ b/src/node.rs
@@ -78,11 +78,9 @@ impl LayoutTree for Taffy {
&mut self.nodes[node].layout
}
- fn mark_dirty(&mut self, node: Node, dirty: bool) {
- self.nodes[node].is_dirty = dirty;
- if dirty {
- self.nodes[node].size_cache = [None; 4];
- }
+ #[inline(always)]
+ fn mark_dirty(&mut self, node: Node) -> TaffyResult<()> {
+ self.mark_dirty_internal(node)
}
fn measure_node(
@@ -210,7 +208,7 @@ impl Taffy {
self.measure_funcs.remove(node);
}
- self.mark_dirty(node)?;
+ self.mark_dirty_internal(node)?;
Ok(())
}
@@ -219,7 +217,7 @@ impl Taffy {
pub fn add_child(&mut self, parent: Node, child: Node) -> TaffyResult<()> {
self.parents[child] = Some(parent);
self.children[parent].push(child);
- self.mark_dirty(parent)?;
+ self.mark_dirty_internal(parent)?;
Ok(())
}
@@ -238,7 +236,7 @@ impl Taffy {
self.children[parent] = children.iter().copied().collect::<_>();
- self.mark_dirty(parent)?;
+ self.mark_dirty_internal(parent)?;
Ok(())
}
@@ -263,7 +261,7 @@ impl Taffy {
let child = self.children[parent].remove(child_index);
self.parents[child] = None;
- self.mark_dirty(parent)?;
+ self.mark_dirty_internal(parent)?;
Ok(child)
}
@@ -281,7 +279,7 @@ impl Taffy {
let old_child = core::mem::replace(&mut self.children[parent][child_index], new_child);
self.parents[old_child] = None;
- self.mark_dirty(parent)?;
+ self.mark_dirty_internal(parent)?;
Ok(old_child)
}
@@ -309,7 +307,7 @@ impl Taffy {
/// Sets the [`Style`] of the provided `node`
pub fn set_style(&mut self, node: Node, style: Style) -> TaffyResult<()> {
self.nodes[node].style = style;
- self.mark_dirty(node)?;
+ self.mark_dirty_internal(node)?;
Ok(())
}
@@ -328,7 +326,7 @@ impl Taffy {
/// Performs a recursive depth-first search up the tree until the root node is reached
///
/// WARNING: this will stack-overflow if the tree contains a cycle
- pub fn mark_dirty(&mut self, node: Node) -> TaffyResult<()> {
+ fn mark_dirty_internal(&mut self, node: Node) -> TaffyResult<()> {
/// WARNING: this will stack-overflow if the tree contains a cycle
fn mark_dirty_recursive(
nodes: &mut SlotMap<Node, NodeData>,
@@ -349,7 +347,7 @@ impl Taffy {
/// Indicates whether the layout of this node (and its children) need to be recomputed
pub fn dirty(&self, node: Node) -> TaffyResult<bool> {
- Ok(self.nodes[node].is_dirty)
+ Ok(self.nodes[node].size_cache.iter().all(|entry| entry.is_none()))
}
/// Updates the stored layout of the provided `node` and its children
diff --git a/src/tree.rs b/src/tree.rs
index cef20af1a..6645234c9 100644
--- a/src/tree.rs
+++ b/src/tree.rs
@@ -1,6 +1,7 @@
//! The baseline requirements of any UI Tree so Taffy can efficiently calculate the layout
use crate::{
+ error::TaffyResult,
layout::{AvailableSpace, Cache, Layout},
prelude::*,
};
@@ -32,7 +33,7 @@ pub trait LayoutTree {
fn layout_mut(&mut self, node: Node) -> &mut Layout;
/// Mark a node as finished
- fn mark_dirty(&mut self, node: Node, dirty: bool);
+ fn mark_dirty(&mut self, node: Node) -> TaffyResult<()>;
/// Measure a node. Taffy uses this to force reflows of things like text and overflowing content.
fn measure_node(