gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definiciones

Fix caching of `display:none` nodes (backport of #454) (#456)

6fc374ff95716cede531bc188aeb69ef0111892f · por Nico Burns · (hace 3 años) · padre 1cc940684 · ver el árbol en este commit

Delta semántico · 3

src/compute/mod.rs

tests/relayout.rs

2 archivos · +38 −0

diff --git a/src/compute/mod.rs b/src/compute/mod.rs
index 35fc1b9b0..6fd974350 100644
--- a/src/compute/mod.rs
+++ b/src/compute/mod.rs
@@ -371,6 +371,9 @@ fn perform_hidden_layout(tree: &mut impl LayoutTree, node: Node) {
     /// Recursive function to apply hidden layout to all descendents
     fn perform_hidden_layout_inner(tree: &mut impl LayoutTree, node: Node, order: u32) {
         *tree.layout_mut(node) = Layout::with_order(order);
+        for i in 0..7 {
+            *tree.cache_mut(node, i) = None;
+        }
         for order in 0..tree.child_count(node) {
             perform_hidden_layout_inner(tree, tree.child(node, order), order as _);
         }
diff --git a/tests/relayout.rs b/tests/relayout.rs
index 1f4695127..2575141ec 100644
--- a/tests/relayout.rs
+++ b/tests/relayout.rs
@@ -101,6 +101,41 @@ fn toggle_root_display_none() {
     assert_eq!(layout.size.height, 0.0);
 }
 
+#[test]
+fn toggle_root_display_none_with_children() {
+    use taffy::prelude::*;
+
+    let mut taffy = taffy::Taffy::new();
+
+    let child = taffy
+        .new_leaf(Style { size: Size { width: points(800.0), height: points(100.0) }, ..Default::default() })
+        .unwrap();
+
+    let parent = taffy
+        .new_with_children(
+            Style { size: Size { width: points(800.0), height: points(100.0) }, ..Default::default() },
+            &[child],
+        )
+        .unwrap();
+
+    let root = taffy.new_with_children(Style::default(), &[parent]).unwrap();
+    taffy.compute_layout(root, Size::MAX_CONTENT).unwrap();
+    assert_eq!(taffy.layout(child).unwrap().size.width, 800.0);
+    assert_eq!(taffy.layout(child).unwrap().size.height, 100.0);
+
+    taffy.set_style(root, Style { display: Display::None, ..Default::default() }).unwrap();
+    taffy.compute_layout(root, Size::MAX_CONTENT).unwrap();
+    assert_eq!(taffy.layout(child).unwrap().size.width, 0.0);
+    assert_eq!(taffy.layout(child).unwrap().size.height, 0.0);
+
+    taffy.set_style(root, Style::default()).unwrap();
+    taffy.compute_layout(root, Size::MAX_CONTENT).unwrap();
+    assert_eq!(taffy.layout(parent).unwrap().size.width, 800.0);
+    assert_eq!(taffy.layout(parent).unwrap().size.height, 100.0);
+    assert_eq!(taffy.layout(child).unwrap().size.width, 800.0);
+    assert_eq!(taffy.layout(child).unwrap().size.height, 100.0);
+}
+
 #[test]
 fn toggle_flex_child_display_none() {
     let hidden_style = Style {