diff --git a/test_fixtures/contents/contents_flex_basic.html b/test_fixtures/contents/contents_flex_basic.html new file mode 100644 index 000000000..014cefe41 --- /dev/null +++ b/test_fixtures/contents/contents_flex_basic.html @@ -0,0 +1,23 @@ + + + + + + + Test description + + + + +
+
+
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/contents/contents_flex_nested.html b/test_fixtures/contents/contents_flex_nested.html new file mode 100644 index 000000000..5f3e847ef --- /dev/null +++ b/test_fixtures/contents/contents_flex_nested.html @@ -0,0 +1,26 @@ + + + + + + + Test description + + + + +
+
+
+
+
+
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/contents/contents_flex_nested2.html b/test_fixtures/contents/contents_flex_nested2.html new file mode 100644 index 000000000..ce8ae1bf5 --- /dev/null +++ b/test_fixtures/contents/contents_flex_nested2.html @@ -0,0 +1,28 @@ + + + + + + + Test description + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/tests/generated/contents/contents_flex_basic.rs b/tests/generated/contents/contents_flex_basic.rs new file mode 100644 index 000000000..0f34cf395 --- /dev/null +++ b/tests/generated/contents/contents_flex_basic.rs @@ -0,0 +1,95 @@ +#[test] +fn contents_flex_basic() { + #[allow(unused_imports)] + use taffy::{prelude::*, tree::Layout}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Length(30f32), height: auto() }, + ..Default::default() + }) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Length(30f32), height: auto() }, + ..Default::default() + }) + .unwrap(); + let node2 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Length(30f32), height: auto() }, + ..Default::default() + }) + .unwrap(); + let node30 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Length(30f32), height: auto() }, + ..Default::default() + }) + .unwrap(); + let node31 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Length(30f32), height: auto() }, + ..Default::default() + }) + .unwrap(); + let node3 = taffy + .new_with_children( + taffy::style::Style { display: taffy::style::Display::Contents, ..Default::default() }, + &[node30, node31], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + justify_content: Some(taffy::style::JustifyContent::SpaceBetween), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(400f32), + height: taffy::style::Dimension::Length(300f32), + }, + ..Default::default() + }, + &[node0, node1, node2, node3], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::util::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node, 400f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node, 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node0, 30f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node0, 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node1).unwrap(); + assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node1, 30f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node1, 300f32, size.height); + assert_eq!(location.x, 93f32, "x of node {:?}. Expected {}. Actual {}", node1, 93f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node2).unwrap(); + assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node2, 30f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node2, 300f32, size.height); + assert_eq!(location.x, 185f32, "x of node {:?}. Expected {}. Actual {}", node2, 185f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node3).unwrap(); + assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node3, 0f32, size.width); + assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node3, 0f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node3, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node30).unwrap(); + assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node30, 30f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node30, 300f32, size.height); + assert_eq!(location.x, 278f32, "x of node {:?}. Expected {}. Actual {}", node30, 278f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node30, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node31).unwrap(); + assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node31, 30f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node31, 300f32, size.height); + assert_eq!(location.x, 370f32, "x of node {:?}. Expected {}. Actual {}", node31, 370f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node31, 0f32, location.y); +} diff --git a/tests/generated/contents/contents_flex_nested.rs b/tests/generated/contents/contents_flex_nested.rs new file mode 100644 index 000000000..a1882adf4 --- /dev/null +++ b/tests/generated/contents/contents_flex_nested.rs @@ -0,0 +1,117 @@ +#[test] +fn contents_flex_nested() { + #[allow(unused_imports)] + use taffy::{prelude::*, tree::Layout}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Length(30f32), height: auto() }, + ..Default::default() + }) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Length(30f32), height: auto() }, + ..Default::default() + }) + .unwrap(); + let node2 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Length(30f32), height: auto() }, + ..Default::default() + }) + .unwrap(); + let node300 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Length(30f32), height: auto() }, + ..Default::default() + }) + .unwrap(); + let node301 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Length(30f32), height: auto() }, + ..Default::default() + }) + .unwrap(); + let node30 = taffy + .new_with_children( + taffy::style::Style { display: taffy::style::Display::Contents, ..Default::default() }, + &[node300, node301], + ) + .unwrap(); + let node31 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Length(30f32), height: auto() }, + ..Default::default() + }) + .unwrap(); + let node3 = taffy + .new_with_children( + taffy::style::Style { display: taffy::style::Display::Contents, ..Default::default() }, + &[node30, node31], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + justify_content: Some(taffy::style::JustifyContent::SpaceBetween), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(400f32), + height: taffy::style::Dimension::Length(300f32), + }, + ..Default::default() + }, + &[node0, node1, node2, node3], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::util::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node, 400f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node, 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node0, 30f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node0, 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node1).unwrap(); + assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node1, 30f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node1, 300f32, size.height); + assert_eq!(location.x, 74f32, "x of node {:?}. Expected {}. Actual {}", node1, 74f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node2).unwrap(); + assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node2, 30f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node2, 300f32, size.height); + assert_eq!(location.x, 148f32, "x of node {:?}. Expected {}. Actual {}", node2, 148f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node3).unwrap(); + assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node3, 0f32, size.width); + assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node3, 0f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node3, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node30).unwrap(); + assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node30, 0f32, size.width); + assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node30, 0f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node30, 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node30, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node300).unwrap(); + assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node300, 30f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node300, 300f32, size.height); + assert_eq!(location.x, 222f32, "x of node {:?}. Expected {}. Actual {}", node300, 222f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node300, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node301).unwrap(); + assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node301, 30f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node301, 300f32, size.height); + assert_eq!(location.x, 296f32, "x of node {:?}. Expected {}. Actual {}", node301, 296f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node301, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node31).unwrap(); + assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node31, 30f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node31, 300f32, size.height); + assert_eq!(location.x, 370f32, "x of node {:?}. Expected {}. Actual {}", node31, 370f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node31, 0f32, location.y); +} diff --git a/tests/generated/contents/contents_flex_nested2.rs b/tests/generated/contents/contents_flex_nested2.rs new file mode 100644 index 000000000..1c94def34 --- /dev/null +++ b/tests/generated/contents/contents_flex_nested2.rs @@ -0,0 +1,128 @@ +#[test] +fn contents_flex_nested2() { + #[allow(unused_imports)] + use taffy::{prelude::*, tree::Layout}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Length(30f32), height: auto() }, + ..Default::default() + }) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Length(30f32), height: auto() }, + ..Default::default() + }) + .unwrap(); + let node20 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Length(30f32), height: auto() }, + ..Default::default() + }) + .unwrap(); + let node2100 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Length(30f32), height: auto() }, + ..Default::default() + }) + .unwrap(); + let node2101 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Length(30f32), height: auto() }, + ..Default::default() + }) + .unwrap(); + let node210 = taffy + .new_with_children( + taffy::style::Style { display: taffy::style::Display::Contents, ..Default::default() }, + &[node2100, node2101], + ) + .unwrap(); + let node211 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Length(30f32), height: auto() }, + ..Default::default() + }) + .unwrap(); + let node21 = taffy + .new_with_children( + taffy::style::Style { display: taffy::style::Display::Contents, ..Default::default() }, + &[node210, node211], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::Style { display: taffy::style::Display::Contents, ..Default::default() }, + &[node20, node21], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + justify_content: Some(taffy::style::JustifyContent::SpaceBetween), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(400f32), + height: taffy::style::Dimension::Length(300f32), + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::util::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node, 400f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node, 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node0, 30f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node0, 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node1).unwrap(); + assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node1, 30f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node1, 300f32, size.height); + assert_eq!(location.x, 74f32, "x of node {:?}. Expected {}. Actual {}", node1, 74f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node2).unwrap(); + assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node2, 0f32, size.width); + assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node2, 0f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node20).unwrap(); + assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node20, 30f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node20, 300f32, size.height); + assert_eq!(location.x, 148f32, "x of node {:?}. Expected {}. Actual {}", node20, 148f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node20, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node21).unwrap(); + assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node21, 0f32, size.width); + assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node21, 0f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node21, 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node21, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node210).unwrap(); + assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node210, 0f32, size.width); + assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node210, 0f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node210, 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node210, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node2100).unwrap(); + assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node2100, 30f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node2100, 300f32, size.height); + assert_eq!(location.x, 222f32, "x of node {:?}. Expected {}. Actual {}", node2100, 222f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2100, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node2101).unwrap(); + assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node2101, 30f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node2101, 300f32, size.height); + assert_eq!(location.x, 296f32, "x of node {:?}. Expected {}. Actual {}", node2101, 296f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2101, 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node211).unwrap(); + assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node211, 30f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node211, 300f32, size.height); + assert_eq!(location.x, 370f32, "x of node {:?}. Expected {}. Actual {}", node211, 370f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node211, 0f32, location.y); +} diff --git a/tests/generated/contents/mod.rs b/tests/generated/contents/mod.rs new file mode 100644 index 000000000..43ced5d4b --- /dev/null +++ b/tests/generated/contents/mod.rs @@ -0,0 +1,3 @@ +mod contents_flex_basic; +mod contents_flex_nested; +mod contents_flex_nested2; diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index e02bffaf5..d09d97e94 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -1,6 +1,7 @@ mod block; mod blockflex; mod blockgrid; +mod contents; mod flex; mod grid; mod gridflex;