-
-
+
diff --git a/tests/generated/grid_percent_simple.rs b/tests/generated/grid_percent_simple.rs
index a8d30d052..cf1aae2da 100644
--- a/tests/generated/grid_percent_simple.rs
+++ b/tests/generated/grid_percent_simple.rs
@@ -4,7 +4,7 @@ fn grid_percent_simple() {
#[allow(unused_imports)]
use taffy::{layout::Layout, prelude::*};
let mut taffy = taffy::Taffy::new();
- let node00 = taffy
+ let node0 = taffy
.new_leaf(taffy::style::Style {
size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.45f32), height: auto() },
margin: taffy::geometry::Rect {
@@ -22,16 +22,11 @@ fn grid_percent_simple() {
..Default::default()
})
.unwrap();
- let node0 = taffy
+ let node = taffy
.new_with_children(
taffy::style::Style {
display: taffy::style::Display::Grid,
- margin: taffy::geometry::Rect {
- left: taffy::style::LengthPercentageAuto::Points(5f32),
- right: taffy::style::LengthPercentageAuto::Points(5f32),
- top: taffy::style::LengthPercentageAuto::Points(5f32),
- bottom: taffy::style::LengthPercentageAuto::Points(5f32),
- },
+ size: taffy::geometry::Size { width: taffy::style::Dimension::Points(200f32), height: auto() },
padding: taffy::geometry::Rect {
left: taffy::style::LengthPercentage::Points(3f32),
right: taffy::style::LengthPercentage::Points(3f32),
@@ -40,22 +35,7 @@ fn grid_percent_simple() {
},
..Default::default()
},
- &[node00],
- )
- .unwrap();
- let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
- let node = taffy
- .new_with_children(
- taffy::style::Style {
- display: taffy::style::Display::Grid,
- grid_template_rows: vec![flex(1f32), flex(4f32)],
- size: taffy::geometry::Size {
- width: taffy::style::Dimension::Points(200f32),
- height: taffy::style::Dimension::Points(200f32),
- },
- ..Default::default()
- },
- &[node0, node1],
+ &[node0],
)
.unwrap();
taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
@@ -64,22 +44,12 @@ fn grid_percent_simple() {
println!();
let Layout { size, location, .. } = taffy.layout(node).unwrap();
assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.width);
- assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.height);
+ assert_eq!(size.height, 31f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 31f32, size.height);
assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
let Layout { size, location, .. } = taffy.layout(node0).unwrap();
- assert_eq!(size.width, 190f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 190f32, size.width);
- assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 30f32, size.height);
- assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 5f32, location.x);
- assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 5f32, location.y);
- let Layout { size, location, .. } = taffy.layout(node00).unwrap();
- assert_eq!(size.width, 83f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 83f32, size.width);
- assert_eq!(size.height, 6f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 6f32, size.height);
- assert_eq!(location.x, 12f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 12f32, location.x);
- assert_eq!(location.y, 12f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 12f32, location.y);
- let Layout { size, location, .. } = taffy.layout(node1).unwrap();
- assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 200f32, size.width);
- assert_eq!(size.height, 160f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 160f32, size.height);
- assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x);
- assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, location.y);
+ assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 87f32, size.width);
+ assert_eq!(size.height, 6f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 6f32, size.height);
+ assert_eq!(location.x, 13f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 13f32, location.x);
+ assert_eq!(location.y, 13f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 13f32, location.y);
}
From 1685b4a15ecb76aa03daff8a1b4808d34fe66e63 Mon Sep 17 00:00:00 2001
From: Nico Burns
Date: Mon, 26 Dec 2022 17:10:01 +0000
Subject: [PATCH 05/12] Disable debug log of cache entries
---
src/compute/mod.rs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/compute/mod.rs b/src/compute/mod.rs
index c0c1ed9b5..427ab9754 100644
--- a/src/compute/mod.rs
+++ b/src/compute/mod.rs
@@ -199,8 +199,8 @@ fn compute_from_cache(
) -> Option> {
for idx in 0..CACHE_SIZE {
let entry = tree.cache_mut(node, idx);
- #[cfg(feature = "debug")]
- NODE_LOGGER.labelled_debug_log("cache_entry", &entry);
+ // #[cfg(feature = "debug")]
+ // NODE_LOGGER.labelled_debug_log("cache_entry", &entry);
if let Some(entry) = entry {
// Cached ComputeSize results are not valid if we are running in PerformLayout mode
if entry.run_mode == RunMode::ComputeSize && run_mode == RunMode::PeformLayout {
From f5e9139033bb77d6a50597d311783b7af5932aed Mon Sep 17 00:00:00 2001
From: Nico Burns
Date: Mon, 26 Dec 2022 18:00:31 +0000
Subject: [PATCH 06/12] Update percent sizing tests
---
.../generated/grid_percent_nested_moderate.rs | 62 ++++++++++++++
...le.rs => grid_percent_width_and_margin.rs} | 0
.../grid_percent_width_and_padding.rs | 28 +++++++
benches/generated/mod.rs | 12 ++-
.../grid_percent_nested_moderate.html | 19 +++++
...tml => grid_percent_width_and_margin.html} | 0
.../grid_percent_width_and_padding.html | 17 ++++
.../generated/grid_percent_nested_moderate.rs | 82 +++++++++++++++++++
...le.rs => grid_percent_width_and_margin.rs} | 2 +-
.../grid_percent_width_and_padding.rs | 43 ++++++++++
tests/generated/mod.rs | 6 +-
11 files changed, 267 insertions(+), 4 deletions(-)
create mode 100644 benches/generated/grid_percent_nested_moderate.rs
rename benches/generated/{grid_percent_simple.rs => grid_percent_width_and_margin.rs} (100%)
create mode 100644 benches/generated/grid_percent_width_and_padding.rs
create mode 100644 test_fixtures/grid_percent_nested_moderate.html
rename test_fixtures/{grid_percent_simple.html => grid_percent_width_and_margin.html} (100%)
create mode 100644 test_fixtures/grid_percent_width_and_padding.html
create mode 100644 tests/generated/grid_percent_nested_moderate.rs
rename tests/generated/{grid_percent_simple.rs => grid_percent_width_and_margin.rs} (98%)
create mode 100644 tests/generated/grid_percent_width_and_padding.rs
diff --git a/benches/generated/grid_percent_nested_moderate.rs b/benches/generated/grid_percent_nested_moderate.rs
new file mode 100644
index 000000000..901105b2d
--- /dev/null
+++ b/benches/generated/grid_percent_nested_moderate.rs
@@ -0,0 +1,62 @@
+pub fn compute() {
+ #[allow(unused_imports)]
+ use taffy::prelude::*;
+ let mut taffy = taffy::Taffy::new();
+ let node00 = taffy
+ .new_leaf(taffy::style::Style {
+ size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.45f32), height: auto() },
+ margin: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentageAuto::Percent(0.05f32),
+ right: taffy::style::LengthPercentageAuto::Percent(0.05f32),
+ top: taffy::style::LengthPercentageAuto::Percent(0.05f32),
+ bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32),
+ },
+ padding: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentage::Points(3f32),
+ right: taffy::style::LengthPercentage::Points(3f32),
+ top: taffy::style::LengthPercentage::Points(3f32),
+ bottom: taffy::style::LengthPercentage::Points(3f32),
+ },
+ ..Default::default()
+ })
+ .unwrap();
+ let node0 = taffy
+ .new_with_children(
+ taffy::style::Style {
+ display: taffy::style::Display::Grid,
+ size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
+ margin: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentageAuto::Points(5f32),
+ right: taffy::style::LengthPercentageAuto::Points(5f32),
+ top: taffy::style::LengthPercentageAuto::Points(5f32),
+ bottom: taffy::style::LengthPercentageAuto::Points(5f32),
+ },
+ padding: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentage::Percent(0.03f32),
+ right: taffy::style::LengthPercentage::Percent(0.03f32),
+ top: taffy::style::LengthPercentage::Percent(0.03f32),
+ bottom: taffy::style::LengthPercentage::Percent(0.03f32),
+ },
+ ..Default::default()
+ },
+ &[node00],
+ )
+ .unwrap();
+ let node = taffy
+ .new_with_children(
+ taffy::style::Style {
+ display: taffy::style::Display::Grid,
+ size: taffy::geometry::Size { width: taffy::style::Dimension::Points(200f32), height: auto() },
+ padding: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentage::Points(3f32),
+ right: taffy::style::LengthPercentage::Points(3f32),
+ top: taffy::style::LengthPercentage::Points(3f32),
+ bottom: taffy::style::LengthPercentage::Points(3f32),
+ },
+ ..Default::default()
+ },
+ &[node0],
+ )
+ .unwrap();
+ taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
+}
diff --git a/benches/generated/grid_percent_simple.rs b/benches/generated/grid_percent_width_and_margin.rs
similarity index 100%
rename from benches/generated/grid_percent_simple.rs
rename to benches/generated/grid_percent_width_and_margin.rs
diff --git a/benches/generated/grid_percent_width_and_padding.rs b/benches/generated/grid_percent_width_and_padding.rs
new file mode 100644
index 000000000..a145b5e86
--- /dev/null
+++ b/benches/generated/grid_percent_width_and_padding.rs
@@ -0,0 +1,28 @@
+pub fn compute() {
+ #[allow(unused_imports)]
+ use taffy::prelude::*;
+ let mut taffy = taffy::Taffy::new();
+ let node0 = taffy
+ .new_leaf(taffy::style::Style {
+ size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
+ padding: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentage::Percent(0.03f32),
+ right: taffy::style::LengthPercentage::Percent(0.03f32),
+ top: taffy::style::LengthPercentage::Percent(0.03f32),
+ bottom: taffy::style::LengthPercentage::Percent(0.03f32),
+ },
+ ..Default::default()
+ })
+ .unwrap();
+ let node = taffy
+ .new_with_children(
+ taffy::style::Style {
+ display: taffy::style::Display::Grid,
+ size: taffy::geometry::Size { width: taffy::style::Dimension::Points(200f32), height: auto() },
+ ..Default::default()
+ },
+ &[node0],
+ )
+ .unwrap();
+ taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
+}
diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs
index e95ddbba3..cad052e73 100644
--- a/benches/generated/mod.rs
+++ b/benches/generated/mod.rs
@@ -405,9 +405,13 @@ mod grid_min_max_column_fixed_width_within_range;
#[cfg(feature = "grid")]
mod grid_out_of_order_items;
#[cfg(feature = "grid")]
+mod grid_percent_nested_moderate;
+#[cfg(feature = "grid")]
mod grid_percent_nested_with_padding_margin;
#[cfg(feature = "grid")]
-mod grid_percent_simple;
+mod grid_percent_width_and_margin;
+#[cfg(feature = "grid")]
+mod grid_percent_width_and_padding;
#[cfg(feature = "grid")]
mod grid_relayout_vertical_text;
#[cfg(feature = "grid")]
@@ -910,9 +914,13 @@ fn benchmark(c: &mut Criterion) {
#[cfg(feature = "grid")]
grid_out_of_order_items::compute();
#[cfg(feature = "grid")]
+ grid_percent_nested_moderate::compute();
+ #[cfg(feature = "grid")]
grid_percent_nested_with_padding_margin::compute();
#[cfg(feature = "grid")]
- grid_percent_simple::compute();
+ grid_percent_width_and_margin::compute();
+ #[cfg(feature = "grid")]
+ grid_percent_width_and_padding::compute();
#[cfg(feature = "grid")]
grid_relayout_vertical_text::compute();
#[cfg(feature = "grid")]
diff --git a/test_fixtures/grid_percent_nested_moderate.html b/test_fixtures/grid_percent_nested_moderate.html
new file mode 100644
index 000000000..9dd670f2f
--- /dev/null
+++ b/test_fixtures/grid_percent_nested_moderate.html
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+ Test description
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/test_fixtures/grid_percent_simple.html b/test_fixtures/grid_percent_width_and_margin.html
similarity index 100%
rename from test_fixtures/grid_percent_simple.html
rename to test_fixtures/grid_percent_width_and_margin.html
diff --git a/test_fixtures/grid_percent_width_and_padding.html b/test_fixtures/grid_percent_width_and_padding.html
new file mode 100644
index 000000000..224516037
--- /dev/null
+++ b/test_fixtures/grid_percent_width_and_padding.html
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+ Test description
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/generated/grid_percent_nested_moderate.rs b/tests/generated/grid_percent_nested_moderate.rs
new file mode 100644
index 000000000..19f0cbba1
--- /dev/null
+++ b/tests/generated/grid_percent_nested_moderate.rs
@@ -0,0 +1,82 @@
+#[test]
+fn grid_percent_nested_moderate() {
+ use slotmap::Key;
+ #[allow(unused_imports)]
+ use taffy::{layout::Layout, prelude::*};
+ let mut taffy = taffy::Taffy::new();
+ let node00 = taffy
+ .new_leaf(taffy::style::Style {
+ size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.45f32), height: auto() },
+ margin: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentageAuto::Percent(0.05f32),
+ right: taffy::style::LengthPercentageAuto::Percent(0.05f32),
+ top: taffy::style::LengthPercentageAuto::Percent(0.05f32),
+ bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32),
+ },
+ padding: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentage::Points(3f32),
+ right: taffy::style::LengthPercentage::Points(3f32),
+ top: taffy::style::LengthPercentage::Points(3f32),
+ bottom: taffy::style::LengthPercentage::Points(3f32),
+ },
+ ..Default::default()
+ })
+ .unwrap();
+ let node0 = taffy
+ .new_with_children(
+ taffy::style::Style {
+ display: taffy::style::Display::Grid,
+ size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
+ margin: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentageAuto::Points(5f32),
+ right: taffy::style::LengthPercentageAuto::Points(5f32),
+ top: taffy::style::LengthPercentageAuto::Points(5f32),
+ bottom: taffy::style::LengthPercentageAuto::Points(5f32),
+ },
+ padding: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentage::Percent(0.03f32),
+ right: taffy::style::LengthPercentage::Percent(0.03f32),
+ top: taffy::style::LengthPercentage::Percent(0.03f32),
+ bottom: taffy::style::LengthPercentage::Percent(0.03f32),
+ },
+ ..Default::default()
+ },
+ &[node00],
+ )
+ .unwrap();
+ let node = taffy
+ .new_with_children(
+ taffy::style::Style {
+ display: taffy::style::Display::Grid,
+ size: taffy::geometry::Size { width: taffy::style::Dimension::Points(200f32), height: auto() },
+ padding: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentage::Points(3f32),
+ right: taffy::style::LengthPercentage::Points(3f32),
+ top: taffy::style::LengthPercentage::Points(3f32),
+ bottom: taffy::style::LengthPercentage::Points(3f32),
+ },
+ ..Default::default()
+ },
+ &[node0],
+ )
+ .unwrap();
+ taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
+ println!("\nComputed tree:");
+ taffy::debug::print_tree(&taffy, node);
+ println!();
+ let Layout { size, location, .. } = taffy.layout(node).unwrap();
+ assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.width);
+ assert_eq!(size.height, 42f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 42f32, size.height);
+ assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
+ assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
+ let Layout { size, location, .. } = taffy.layout(node0).unwrap();
+ assert_eq!(size.width, 97f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 97f32, size.width);
+ assert_eq!(size.height, 26f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 26f32, size.height);
+ assert_eq!(location.x, 8f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 8f32, location.x);
+ assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 8f32, location.y);
+ let Layout { size, location, .. } = taffy.layout(node00).unwrap();
+ assert_eq!(size.width, 38f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 38f32, size.width);
+ assert_eq!(size.height, 6f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 6f32, size.height);
+ assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 10f32, location.x);
+ assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 10f32, location.y);
+}
diff --git a/tests/generated/grid_percent_simple.rs b/tests/generated/grid_percent_width_and_margin.rs
similarity index 98%
rename from tests/generated/grid_percent_simple.rs
rename to tests/generated/grid_percent_width_and_margin.rs
index cf1aae2da..4db83e269 100644
--- a/tests/generated/grid_percent_simple.rs
+++ b/tests/generated/grid_percent_width_and_margin.rs
@@ -1,5 +1,5 @@
#[test]
-fn grid_percent_simple() {
+fn grid_percent_width_and_margin() {
use slotmap::Key;
#[allow(unused_imports)]
use taffy::{layout::Layout, prelude::*};
diff --git a/tests/generated/grid_percent_width_and_padding.rs b/tests/generated/grid_percent_width_and_padding.rs
new file mode 100644
index 000000000..e9d8e0c0c
--- /dev/null
+++ b/tests/generated/grid_percent_width_and_padding.rs
@@ -0,0 +1,43 @@
+#[test]
+fn grid_percent_width_and_padding() {
+ use slotmap::Key;
+ #[allow(unused_imports)]
+ use taffy::{layout::Layout, prelude::*};
+ let mut taffy = taffy::Taffy::new();
+ let node0 = taffy
+ .new_leaf(taffy::style::Style {
+ size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
+ padding: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentage::Percent(0.03f32),
+ right: taffy::style::LengthPercentage::Percent(0.03f32),
+ top: taffy::style::LengthPercentage::Percent(0.03f32),
+ bottom: taffy::style::LengthPercentage::Percent(0.03f32),
+ },
+ ..Default::default()
+ })
+ .unwrap();
+ let node = taffy
+ .new_with_children(
+ taffy::style::Style {
+ display: taffy::style::Display::Grid,
+ size: taffy::geometry::Size { width: taffy::style::Dimension::Points(200f32), height: auto() },
+ ..Default::default()
+ },
+ &[node0],
+ )
+ .unwrap();
+ taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
+ println!("\nComputed tree:");
+ taffy::debug::print_tree(&taffy, node);
+ println!();
+ let Layout { size, location, .. } = taffy.layout(node).unwrap();
+ assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.width);
+ assert_eq!(size.height, 12f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 12f32, size.height);
+ assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
+ assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
+ let Layout { size, location, .. } = taffy.layout(node0).unwrap();
+ assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.width);
+ assert_eq!(size.height, 12f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 12f32, size.height);
+ assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
+ assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
+}
diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs
index 0d74b5de1..4e8786838 100644
--- a/tests/generated/mod.rs
+++ b/tests/generated/mod.rs
@@ -404,9 +404,13 @@ mod grid_min_max_column_fixed_width_within_range;
#[cfg(feature = "grid")]
mod grid_out_of_order_items;
#[cfg(feature = "grid")]
+mod grid_percent_nested_moderate;
+#[cfg(feature = "grid")]
mod grid_percent_nested_with_padding_margin;
#[cfg(feature = "grid")]
-mod grid_percent_simple;
+mod grid_percent_width_and_margin;
+#[cfg(feature = "grid")]
+mod grid_percent_width_and_padding;
#[cfg(feature = "grid")]
mod grid_relayout_vertical_text;
#[cfg(feature = "grid")]
From 45513666376011740401a19635a5606892f85644 Mon Sep 17 00:00:00 2001
From: Nico Burns
Date: Thu, 29 Dec 2022 21:23:32 +0000
Subject: [PATCH 07/12] Add moderate complexity percentage test for flexbox
algorithm
---
benches/generated/mod.rs | 2 +
.../percentage_moderate_complexity.rs | 64 ++++++++++++++
.../percentage_moderate_complexity.html | 19 +++++
tests/generated/mod.rs | 1 +
.../percentage_moderate_complexity.rs | 84 +++++++++++++++++++
5 files changed, 170 insertions(+)
create mode 100644 benches/generated/percentage_moderate_complexity.rs
create mode 100644 test_fixtures/percentage_moderate_complexity.html
create mode 100644 tests/generated/percentage_moderate_complexity.rs
diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs
index cad052e73..ea7234c7d 100644
--- a/benches/generated/mod.rs
+++ b/benches/generated/mod.rs
@@ -520,6 +520,7 @@ mod percentage_flex_basis_main_max_height;
mod percentage_flex_basis_main_max_width;
mod percentage_flex_basis_main_min_width;
mod percentage_margin_should_calculate_based_only_on_width;
+mod percentage_moderate_complexity;
mod percentage_multiple_nested_with_padding_margin_and_percentage_values;
mod percentage_padding_should_calculate_based_only_on_width;
mod percentage_position_bottom_right;
@@ -1029,6 +1030,7 @@ fn benchmark(c: &mut Criterion) {
percentage_flex_basis_main_max_width::compute();
percentage_flex_basis_main_min_width::compute();
percentage_margin_should_calculate_based_only_on_width::compute();
+ percentage_moderate_complexity::compute();
percentage_multiple_nested_with_padding_margin_and_percentage_values::compute();
percentage_padding_should_calculate_based_only_on_width::compute();
percentage_position_bottom_right::compute();
diff --git a/benches/generated/percentage_moderate_complexity.rs b/benches/generated/percentage_moderate_complexity.rs
new file mode 100644
index 000000000..cc733968b
--- /dev/null
+++ b/benches/generated/percentage_moderate_complexity.rs
@@ -0,0 +1,64 @@
+pub fn compute() {
+ #[allow(unused_imports)]
+ use taffy::prelude::*;
+ let mut taffy = taffy::Taffy::new();
+ let node00 = taffy
+ .new_leaf(taffy::style::Style {
+ size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.45f32), height: auto() },
+ margin: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentageAuto::Percent(0.05f32),
+ right: taffy::style::LengthPercentageAuto::Percent(0.05f32),
+ top: taffy::style::LengthPercentageAuto::Percent(0.05f32),
+ bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32),
+ },
+ padding: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentage::Points(3f32),
+ right: taffy::style::LengthPercentage::Points(3f32),
+ top: taffy::style::LengthPercentage::Points(3f32),
+ bottom: taffy::style::LengthPercentage::Points(3f32),
+ },
+ ..Default::default()
+ })
+ .unwrap();
+ let node0 = taffy
+ .new_with_children(
+ taffy::style::Style {
+ display: taffy::style::Display::Flex,
+ flex_direction: taffy::style::FlexDirection::Column,
+ size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
+ margin: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentageAuto::Points(5f32),
+ right: taffy::style::LengthPercentageAuto::Points(5f32),
+ top: taffy::style::LengthPercentageAuto::Points(5f32),
+ bottom: taffy::style::LengthPercentageAuto::Points(5f32),
+ },
+ padding: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentage::Percent(0.03f32),
+ right: taffy::style::LengthPercentage::Percent(0.03f32),
+ top: taffy::style::LengthPercentage::Percent(0.03f32),
+ bottom: taffy::style::LengthPercentage::Percent(0.03f32),
+ },
+ ..Default::default()
+ },
+ &[node00],
+ )
+ .unwrap();
+ let node = taffy
+ .new_with_children(
+ taffy::style::Style {
+ display: taffy::style::Display::Flex,
+ flex_direction: taffy::style::FlexDirection::Column,
+ size: taffy::geometry::Size { width: taffy::style::Dimension::Points(200f32), height: auto() },
+ padding: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentage::Points(3f32),
+ right: taffy::style::LengthPercentage::Points(3f32),
+ top: taffy::style::LengthPercentage::Points(3f32),
+ bottom: taffy::style::LengthPercentage::Points(3f32),
+ },
+ ..Default::default()
+ },
+ &[node0],
+ )
+ .unwrap();
+ taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
+}
diff --git a/test_fixtures/percentage_moderate_complexity.html b/test_fixtures/percentage_moderate_complexity.html
new file mode 100644
index 000000000..ce93de9ce
--- /dev/null
+++ b/test_fixtures/percentage_moderate_complexity.html
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+ Test description
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs
index 4e8786838..30442ab48 100644
--- a/tests/generated/mod.rs
+++ b/tests/generated/mod.rs
@@ -519,6 +519,7 @@ mod percentage_flex_basis_main_max_height;
mod percentage_flex_basis_main_max_width;
mod percentage_flex_basis_main_min_width;
mod percentage_margin_should_calculate_based_only_on_width;
+mod percentage_moderate_complexity;
mod percentage_multiple_nested_with_padding_margin_and_percentage_values;
mod percentage_padding_should_calculate_based_only_on_width;
mod percentage_position_bottom_right;
diff --git a/tests/generated/percentage_moderate_complexity.rs b/tests/generated/percentage_moderate_complexity.rs
new file mode 100644
index 000000000..87df70f35
--- /dev/null
+++ b/tests/generated/percentage_moderate_complexity.rs
@@ -0,0 +1,84 @@
+#[test]
+fn percentage_moderate_complexity() {
+ use slotmap::Key;
+ #[allow(unused_imports)]
+ use taffy::{layout::Layout, prelude::*};
+ let mut taffy = taffy::Taffy::new();
+ let node00 = taffy
+ .new_leaf(taffy::style::Style {
+ size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.45f32), height: auto() },
+ margin: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentageAuto::Percent(0.05f32),
+ right: taffy::style::LengthPercentageAuto::Percent(0.05f32),
+ top: taffy::style::LengthPercentageAuto::Percent(0.05f32),
+ bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32),
+ },
+ padding: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentage::Points(3f32),
+ right: taffy::style::LengthPercentage::Points(3f32),
+ top: taffy::style::LengthPercentage::Points(3f32),
+ bottom: taffy::style::LengthPercentage::Points(3f32),
+ },
+ ..Default::default()
+ })
+ .unwrap();
+ let node0 = taffy
+ .new_with_children(
+ taffy::style::Style {
+ display: taffy::style::Display::Flex,
+ flex_direction: taffy::style::FlexDirection::Column,
+ size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
+ margin: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentageAuto::Points(5f32),
+ right: taffy::style::LengthPercentageAuto::Points(5f32),
+ top: taffy::style::LengthPercentageAuto::Points(5f32),
+ bottom: taffy::style::LengthPercentageAuto::Points(5f32),
+ },
+ padding: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentage::Percent(0.03f32),
+ right: taffy::style::LengthPercentage::Percent(0.03f32),
+ top: taffy::style::LengthPercentage::Percent(0.03f32),
+ bottom: taffy::style::LengthPercentage::Percent(0.03f32),
+ },
+ ..Default::default()
+ },
+ &[node00],
+ )
+ .unwrap();
+ let node = taffy
+ .new_with_children(
+ taffy::style::Style {
+ display: taffy::style::Display::Flex,
+ flex_direction: taffy::style::FlexDirection::Column,
+ size: taffy::geometry::Size { width: taffy::style::Dimension::Points(200f32), height: auto() },
+ padding: taffy::geometry::Rect {
+ left: taffy::style::LengthPercentage::Points(3f32),
+ right: taffy::style::LengthPercentage::Points(3f32),
+ top: taffy::style::LengthPercentage::Points(3f32),
+ bottom: taffy::style::LengthPercentage::Points(3f32),
+ },
+ ..Default::default()
+ },
+ &[node0],
+ )
+ .unwrap();
+ taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
+ println!("\nComputed tree:");
+ taffy::debug::print_tree(&taffy, node);
+ println!();
+ let Layout { size, location, .. } = taffy.layout(node).unwrap();
+ assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.width);
+ assert_eq!(size.height, 42f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 42f32, size.height);
+ assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
+ assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
+ let Layout { size, location, .. } = taffy.layout(node0).unwrap();
+ assert_eq!(size.width, 97f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 97f32, size.width);
+ assert_eq!(size.height, 26f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 26f32, size.height);
+ assert_eq!(location.x, 8f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 8f32, location.x);
+ assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 8f32, location.y);
+ let Layout { size, location, .. } = taffy.layout(node00).unwrap();
+ assert_eq!(size.width, 38f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 38f32, size.width);
+ assert_eq!(size.height, 6f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 6f32, size.height);
+ assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 10f32, location.x);
+ assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 10f32, location.y);
+}
From 665c7f6bd907bc1f77c2c6a4b6409cbc0ec8dc23 Mon Sep 17 00:00:00 2001
From: Nico Burns
Date: Thu, 29 Dec 2022 21:24:26 +0000
Subject: [PATCH 08/12] Introduce parent size parameter to layout algorithm +
percentage sizing fixes
---
src/compute/flexbox.rs | 77 +++++++++++++++++++----------
src/compute/grid/alignment.rs | 23 ++++++---
src/compute/grid/mod.rs | 53 ++++++++++++++------
src/compute/grid/track_sizing.rs | 41 +++++++++------
src/compute/grid/types/grid_item.rs | 7 ++-
src/compute/leaf.rs | 11 +++--
src/compute/mod.rs | 18 +++++--
7 files changed, 154 insertions(+), 76 deletions(-)
diff --git a/src/compute/flexbox.rs b/src/compute/flexbox.rs
index 1c39fc3b0..a39871bc7 100644
--- a/src/compute/flexbox.rs
+++ b/src/compute/flexbox.rs
@@ -117,9 +117,12 @@ struct AlgoConstants {
/// The align_items property of this node
align_items: AlignItems,
- /// The size of the internal node
+ /// The border-box size of the node being laid out (if known)
+ node_outer_size: Size