From 25571b5d07206880207e451af69dd3b49b113628 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Tue, 16 Jul 2024 17:33:00 +1200 Subject: [PATCH] Fix resolving flexible lengths (WPT css/flexbox-multiline-min-max test) (#692) * Port failing multiline-min-max tests from WPT * Don't assume that we are flex-shrinking just because we are not flex-growing (we may be exactly sized) * Don't double count margins when calculating free space when resolving flexible lengths --- src/compute/flexbox.rs | 32 +- test_fixtures/flex/multiline_min_max_12.html | 32 ++ test_fixtures/flex/multiline_min_max_13.html | 32 ++ test_fixtures/flex/multiline_min_max_14.html | 32 ++ test_fixtures/flex/multiline_min_max_5.html | 32 ++ test_fixtures/flex/multiline_min_max_8.html | 32 ++ tests/generated/flex/mod.rs | 5 + tests/generated/flex/multiline_min_max_12.rs | 409 ++++++++++++++++++ tests/generated/flex/multiline_min_max_13.rs | 409 ++++++++++++++++++ tests/generated/flex/multiline_min_max_14.rs | 409 ++++++++++++++++++ tests/generated/flex/multiline_min_max_5.rs | 405 ++++++++++++++++++ tests/generated/flex/multiline_min_max_8.rs | 413 +++++++++++++++++++ 12 files changed, 2231 insertions(+), 11 deletions(-) create mode 100644 test_fixtures/flex/multiline_min_max_12.html create mode 100644 test_fixtures/flex/multiline_min_max_13.html create mode 100644 test_fixtures/flex/multiline_min_max_14.html create mode 100644 test_fixtures/flex/multiline_min_max_5.html create mode 100644 test_fixtures/flex/multiline_min_max_8.html create mode 100644 tests/generated/flex/multiline_min_max_12.rs create mode 100644 tests/generated/flex/multiline_min_max_13.rs create mode 100644 tests/generated/flex/multiline_min_max_14.rs create mode 100644 tests/generated/flex/multiline_min_max_5.rs create mode 100644 tests/generated/flex/multiline_min_max_8.rs diff --git a/src/compute/flexbox.rs b/src/compute/flexbox.rs index 371e05afd..2ce9ec16d 100644 --- a/src/compute/flexbox.rs +++ b/src/compute/flexbox.rs @@ -261,7 +261,6 @@ fn compute_preliminary(tree: &mut impl LayoutFlexboxContainer, node: NodeId, inp // If container size is undefined, determine the container's main size // and then re-resolve gaps based on newly determined size debug_log!("determine_container_main_size"); - let original_gap = constants.gap; if let Some(inner_main_size) = constants.node_inner_size.main(constants.dir) { let outer_main_size = inner_main_size + constants.content_box_inset.main_axis_sum(constants.dir); constants.inner_container_size.set_main(constants.dir, inner_main_size); @@ -285,7 +284,7 @@ fn compute_preliminary(tree: &mut impl LayoutFlexboxContainer, node: NodeId, inp // 6. Resolve the flexible lengths of all the flex items to find their used main size. debug_log!("resolve_flexible_lengths"); for line in &mut flex_lines { - resolve_flexible_lengths(line, &constants, original_gap); + resolve_flexible_lengths(line, &constants); } // 9.4. Cross Size Determination @@ -1105,8 +1104,7 @@ fn determine_container_main_size( /// /// # [9.7. Resolving Flexible Lengths](https://www.w3.org/TR/css-flexbox-1/#resolve-flexible-lengths) #[inline] -fn resolve_flexible_lengths(line: &mut FlexLine, constants: &AlgoConstants, original_gap: Size) { - let total_original_main_axis_gap = sum_axis_gaps(original_gap.main(constants.dir), line.items.len()); +fn resolve_flexible_lengths(line: &mut FlexLine, constants: &AlgoConstants) { let total_main_axis_gap = sum_axis_gaps(constants.gap.main(constants.dir), line.items.len()); // 1. Determine the used flex factor. Sum the outer hypothetical main sizes of all @@ -1116,9 +1114,10 @@ fn resolve_flexible_lengths(line: &mut FlexLine, constants: &AlgoConstants, orig let total_hypothetical_outer_main_size = line.items.iter().map(|child| child.hypothetical_outer_size.main(constants.dir)).sum::(); - let used_flex_factor: f32 = total_original_main_axis_gap + total_hypothetical_outer_main_size; + let used_flex_factor: f32 = total_main_axis_gap + total_hypothetical_outer_main_size; let growing = used_flex_factor < constants.node_inner_size.main(constants.dir).unwrap_or(0.0); - let shrinking = !growing; + let shrinking = used_flex_factor > constants.node_inner_size.main(constants.dir).unwrap_or(0.0); + let exactly_sized = !growing & !shrinking; // 2. Size inflexible items. Freeze, setting its target main size to its hypothetical main size // - Any item that has a flex factor of zero @@ -1131,7 +1130,8 @@ fn resolve_flexible_lengths(line: &mut FlexLine, constants: &AlgoConstants, orig let inner_target_size = child.hypothetical_inner_size.main(constants.dir); child.target_size.set_main(constants.dir, inner_target_size); - if (child.flex_grow == 0.0 && child.flex_shrink == 0.0) + if exactly_sized + || (child.flex_grow == 0.0 && child.flex_shrink == 0.0) || (growing && child.flex_basis > child.hypothetical_inner_size.main(constants.dir)) || (shrinking && child.flex_basis < child.hypothetical_inner_size.main(constants.dir)) { @@ -1141,6 +1141,10 @@ fn resolve_flexible_lengths(line: &mut FlexLine, constants: &AlgoConstants, orig } } + if exactly_sized { + return; + } + // 3. Calculate initial free space. Sum the outer sizes of all items on the line, // and subtract this from the flex container’s inner main size. For frozen items, // use their outer target main size; for other items, use their outer flex base size. @@ -1150,8 +1154,11 @@ fn resolve_flexible_lengths(line: &mut FlexLine, constants: &AlgoConstants, orig .items .iter() .map(|child| { - child.margin.main_axis_sum(constants.dir) - + if child.frozen { child.outer_target_size.main(constants.dir) } else { child.flex_basis } + if child.frozen { + child.outer_target_size.main(constants.dir) + } else { + child.flex_basis + child.margin.main_axis_sum(constants.dir) + } }) .sum::(); @@ -1178,8 +1185,11 @@ fn resolve_flexible_lengths(line: &mut FlexLine, constants: &AlgoConstants, orig .items .iter() .map(|child| { - child.margin.main_axis_sum(constants.dir) - + if child.frozen { child.outer_target_size.main(constants.dir) } else { child.flex_basis } + if child.frozen { + child.outer_target_size.main(constants.dir) + } else { + child.flex_basis + child.margin.main_axis_sum(constants.dir) + } }) .sum::(); diff --git a/test_fixtures/flex/multiline_min_max_12.html b/test_fixtures/flex/multiline_min_max_12.html new file mode 100644 index 000000000..565f1e6d0 --- /dev/null +++ b/test_fixtures/flex/multiline_min_max_12.html @@ -0,0 +1,32 @@ + + + + + + + + + + Test description + + + + +
+
+
+
+
+
+ + + diff --git a/test_fixtures/flex/multiline_min_max_13.html b/test_fixtures/flex/multiline_min_max_13.html new file mode 100644 index 000000000..491ccb878 --- /dev/null +++ b/test_fixtures/flex/multiline_min_max_13.html @@ -0,0 +1,32 @@ + + + + + + + + + + Test description + + + + +
+
+
+
+
+
+ + + diff --git a/test_fixtures/flex/multiline_min_max_14.html b/test_fixtures/flex/multiline_min_max_14.html new file mode 100644 index 000000000..4d177f5d6 --- /dev/null +++ b/test_fixtures/flex/multiline_min_max_14.html @@ -0,0 +1,32 @@ + + + + + + + + + + Test description + + + + +
+
+
+
+
+
+ + + diff --git a/test_fixtures/flex/multiline_min_max_5.html b/test_fixtures/flex/multiline_min_max_5.html new file mode 100644 index 000000000..adacd15de --- /dev/null +++ b/test_fixtures/flex/multiline_min_max_5.html @@ -0,0 +1,32 @@ + + + + + + + + + + Test description + + + + +
+
+
+
+
+
+ + + diff --git a/test_fixtures/flex/multiline_min_max_8.html b/test_fixtures/flex/multiline_min_max_8.html new file mode 100644 index 000000000..4cc8f3b58 --- /dev/null +++ b/test_fixtures/flex/multiline_min_max_8.html @@ -0,0 +1,32 @@ + + + + + + + + + + Test description + + + + +
+
+
+
+
+
+ + + diff --git a/tests/generated/flex/mod.rs b/tests/generated/flex/mod.rs index b20d6fcd5..91c6edd13 100644 --- a/tests/generated/flex/mod.rs +++ b/tests/generated/flex/mod.rs @@ -411,6 +411,11 @@ mod min_width_larger_than_width; mod min_width_overrides_max_width; mod min_width_overrides_width; mod min_width_overrides_width_on_root; +mod multiline_min_max_12; +mod multiline_min_max_13; +mod multiline_min_max_14; +mod multiline_min_max_5; +mod multiline_min_max_8; mod nested_overflowing_child; mod nested_overflowing_child_in_constraint_parent; mod only_shrinkable_item_with_flex_basis_zero; diff --git a/tests/generated/flex/multiline_min_max_12.rs b/tests/generated/flex/multiline_min_max_12.rs new file mode 100644 index 000000000..e6871ba82 --- /dev/null +++ b/tests/generated/flex/multiline_min_max_12.rs @@ -0,0 +1,409 @@ +#[test] +#[allow(non_snake_case)] +fn multiline_min_max_12__border_box() { + #[allow(unused_imports)] + use taffy::{prelude::*, tree::Layout, TaffyTree}; + let mut taffy: TaffyTree = TaffyTree::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Length(600f32), + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) }, + max_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(300f32), height: auto() }, + padding: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Length(10f32), + right: zero(), + top: zero(), + bottom: zero(), + }, + ..Default::default() + }) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node2 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node3 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_wrap: taffy::style::FlexWrap::Wrap, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(600f32), + height: taffy::style::Dimension::Length(20f32), + }, + border: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Length(5f32), + right: taffy::style::LengthPercentage::Length(5f32), + top: taffy::style::LengthPercentage::Length(5f32), + bottom: taffy::style::LengthPercentage::Length(5f32), + }, + ..Default::default() + }, + &[node0, node1, node2, node3], + ) + .unwrap(); + taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap(); + println!("\nComputed tree:"); + taffy.print_tree(node); + println!(); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 610f32, "width of node {:?}. Expected {}. Actual {}", node, 610f32, size.width); + assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, 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); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node0, 300f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height); + assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node0, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node0, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height); + assert_eq!(location.x, 305f32, "x of node {:?}. Expected {}. Actual {}", node1, 305f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node1, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node1, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node1, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height); + assert_eq!(location.x, 405f32, "x of node {:?}. Expected {}. Actual {}", node2, 405f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node2, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node2, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node2, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node3, 100f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height); + assert_eq!(location.x, 505f32, "x of node {:?}. Expected {}. Actual {}", node3, 505f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node3, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node3, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node3, + 0f32, + layout.scroll_height() + ); +} + +#[test] +#[allow(non_snake_case)] +fn multiline_min_max_12__content_box() { + #[allow(unused_imports)] + use taffy::{prelude::*, tree::Layout, TaffyTree}; + let mut taffy: TaffyTree = TaffyTree::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Length(600f32), + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) }, + max_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(300f32), height: auto() }, + padding: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Length(10f32), + right: zero(), + top: zero(), + bottom: zero(), + }, + ..Default::default() + }) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node2 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node3 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_wrap: taffy::style::FlexWrap::Wrap, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(600f32), + height: taffy::style::Dimension::Length(20f32), + }, + border: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Length(5f32), + right: taffy::style::LengthPercentage::Length(5f32), + top: taffy::style::LengthPercentage::Length(5f32), + bottom: taffy::style::LengthPercentage::Length(5f32), + }, + ..Default::default() + }, + &[node0, node1, node2, node3], + ) + .unwrap(); + taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap(); + println!("\nComputed tree:"); + taffy.print_tree(node); + println!(); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 610f32, "width of node {:?}. Expected {}. Actual {}", node, 610f32, size.width); + assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, 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); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node0, 300f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height); + assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node0, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node0, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height); + assert_eq!(location.x, 305f32, "x of node {:?}. Expected {}. Actual {}", node1, 305f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node1, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node1, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node1, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height); + assert_eq!(location.x, 405f32, "x of node {:?}. Expected {}. Actual {}", node2, 405f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node2, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node2, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node2, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node3, 100f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height); + assert_eq!(location.x, 505f32, "x of node {:?}. Expected {}. Actual {}", node3, 505f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node3, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node3, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node3, + 0f32, + layout.scroll_height() + ); +} diff --git a/tests/generated/flex/multiline_min_max_13.rs b/tests/generated/flex/multiline_min_max_13.rs new file mode 100644 index 000000000..8a237eb6f --- /dev/null +++ b/tests/generated/flex/multiline_min_max_13.rs @@ -0,0 +1,409 @@ +#[test] +#[allow(non_snake_case)] +fn multiline_min_max_13__border_box() { + #[allow(unused_imports)] + use taffy::{prelude::*, tree::Layout, TaffyTree}; + let mut taffy: TaffyTree = TaffyTree::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Length(600f32), + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) }, + max_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(300f32), height: auto() }, + border: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Length(10f32), + right: zero(), + top: zero(), + bottom: zero(), + }, + ..Default::default() + }) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node2 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node3 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_wrap: taffy::style::FlexWrap::Wrap, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(600f32), + height: taffy::style::Dimension::Length(20f32), + }, + border: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Length(5f32), + right: taffy::style::LengthPercentage::Length(5f32), + top: taffy::style::LengthPercentage::Length(5f32), + bottom: taffy::style::LengthPercentage::Length(5f32), + }, + ..Default::default() + }, + &[node0, node1, node2, node3], + ) + .unwrap(); + taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap(); + println!("\nComputed tree:"); + taffy.print_tree(node); + println!(); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 610f32, "width of node {:?}. Expected {}. Actual {}", node, 610f32, size.width); + assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, 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); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node0, 300f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height); + assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node0, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node0, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height); + assert_eq!(location.x, 305f32, "x of node {:?}. Expected {}. Actual {}", node1, 305f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node1, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node1, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node1, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height); + assert_eq!(location.x, 405f32, "x of node {:?}. Expected {}. Actual {}", node2, 405f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node2, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node2, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node2, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node3, 100f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height); + assert_eq!(location.x, 505f32, "x of node {:?}. Expected {}. Actual {}", node3, 505f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node3, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node3, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node3, + 0f32, + layout.scroll_height() + ); +} + +#[test] +#[allow(non_snake_case)] +fn multiline_min_max_13__content_box() { + #[allow(unused_imports)] + use taffy::{prelude::*, tree::Layout, TaffyTree}; + let mut taffy: TaffyTree = TaffyTree::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Length(600f32), + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) }, + max_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(300f32), height: auto() }, + border: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Length(10f32), + right: zero(), + top: zero(), + bottom: zero(), + }, + ..Default::default() + }) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node2 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node3 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_wrap: taffy::style::FlexWrap::Wrap, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(600f32), + height: taffy::style::Dimension::Length(20f32), + }, + border: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Length(5f32), + right: taffy::style::LengthPercentage::Length(5f32), + top: taffy::style::LengthPercentage::Length(5f32), + bottom: taffy::style::LengthPercentage::Length(5f32), + }, + ..Default::default() + }, + &[node0, node1, node2, node3], + ) + .unwrap(); + taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap(); + println!("\nComputed tree:"); + taffy.print_tree(node); + println!(); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 610f32, "width of node {:?}. Expected {}. Actual {}", node, 610f32, size.width); + assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, 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); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node0, 300f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height); + assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node0, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node0, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height); + assert_eq!(location.x, 305f32, "x of node {:?}. Expected {}. Actual {}", node1, 305f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node1, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node1, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node1, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height); + assert_eq!(location.x, 405f32, "x of node {:?}. Expected {}. Actual {}", node2, 405f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node2, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node2, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node2, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node3, 100f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height); + assert_eq!(location.x, 505f32, "x of node {:?}. Expected {}. Actual {}", node3, 505f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node3, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node3, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node3, + 0f32, + layout.scroll_height() + ); +} diff --git a/tests/generated/flex/multiline_min_max_14.rs b/tests/generated/flex/multiline_min_max_14.rs new file mode 100644 index 000000000..af21db8ee --- /dev/null +++ b/tests/generated/flex/multiline_min_max_14.rs @@ -0,0 +1,409 @@ +#[test] +#[allow(non_snake_case)] +fn multiline_min_max_14__border_box() { + #[allow(unused_imports)] + use taffy::{prelude::*, tree::Layout, TaffyTree}; + let mut taffy: TaffyTree = TaffyTree::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Length(600f32), + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) }, + max_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(300f32), height: auto() }, + margin: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Length(10f32), + right: zero(), + top: zero(), + bottom: zero(), + }, + ..Default::default() + }) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node2 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node3 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_wrap: taffy::style::FlexWrap::Wrap, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(600f32), + height: taffy::style::Dimension::Length(20f32), + }, + border: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Length(5f32), + right: taffy::style::LengthPercentage::Length(5f32), + top: taffy::style::LengthPercentage::Length(5f32), + bottom: taffy::style::LengthPercentage::Length(5f32), + }, + ..Default::default() + }, + &[node0, node1, node2, node3], + ) + .unwrap(); + taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap(); + println!("\nComputed tree:"); + taffy.print_tree(node); + println!(); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 610f32, "width of node {:?}. Expected {}. Actual {}", node, 610f32, size.width); + assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, 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); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node0, 300f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height); + assert_eq!(location.x, 15f32, "x of node {:?}. Expected {}. Actual {}", node0, 15f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node0, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node0, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap(); + assert_eq!(size.width, 145f32, "width of node {:?}. Expected {}. Actual {}", node1, 145f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height); + assert_eq!(location.x, 315f32, "x of node {:?}. Expected {}. Actual {}", node1, 315f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node1, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node1, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node1, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap(); + assert_eq!(size.width, 145f32, "width of node {:?}. Expected {}. Actual {}", node2, 145f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height); + assert_eq!(location.x, 460f32, "x of node {:?}. Expected {}. Actual {}", node2, 460f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node2, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node2, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node2, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap(); + assert_eq!(size.width, 600f32, "width of node {:?}. Expected {}. Actual {}", node3, 600f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height); + assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node3, 5f32, location.x); + assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node3, 15f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node3, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node3, + 0f32, + layout.scroll_height() + ); +} + +#[test] +#[allow(non_snake_case)] +fn multiline_min_max_14__content_box() { + #[allow(unused_imports)] + use taffy::{prelude::*, tree::Layout, TaffyTree}; + let mut taffy: TaffyTree = TaffyTree::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Length(600f32), + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) }, + max_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(300f32), height: auto() }, + margin: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Length(10f32), + right: zero(), + top: zero(), + bottom: zero(), + }, + ..Default::default() + }) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node2 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node3 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_wrap: taffy::style::FlexWrap::Wrap, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(600f32), + height: taffy::style::Dimension::Length(20f32), + }, + border: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Length(5f32), + right: taffy::style::LengthPercentage::Length(5f32), + top: taffy::style::LengthPercentage::Length(5f32), + bottom: taffy::style::LengthPercentage::Length(5f32), + }, + ..Default::default() + }, + &[node0, node1, node2, node3], + ) + .unwrap(); + taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap(); + println!("\nComputed tree:"); + taffy.print_tree(node); + println!(); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 610f32, "width of node {:?}. Expected {}. Actual {}", node, 610f32, size.width); + assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, 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); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node0, 300f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height); + assert_eq!(location.x, 15f32, "x of node {:?}. Expected {}. Actual {}", node0, 15f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node0, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node0, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap(); + assert_eq!(size.width, 145f32, "width of node {:?}. Expected {}. Actual {}", node1, 145f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height); + assert_eq!(location.x, 315f32, "x of node {:?}. Expected {}. Actual {}", node1, 315f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node1, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node1, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node1, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap(); + assert_eq!(size.width, 145f32, "width of node {:?}. Expected {}. Actual {}", node2, 145f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height); + assert_eq!(location.x, 460f32, "x of node {:?}. Expected {}. Actual {}", node2, 460f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node2, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node2, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node2, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap(); + assert_eq!(size.width, 600f32, "width of node {:?}. Expected {}. Actual {}", node3, 600f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height); + assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node3, 5f32, location.x); + assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node3, 15f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node3, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node3, + 0f32, + layout.scroll_height() + ); +} diff --git a/tests/generated/flex/multiline_min_max_5.rs b/tests/generated/flex/multiline_min_max_5.rs new file mode 100644 index 000000000..08581df56 --- /dev/null +++ b/tests/generated/flex/multiline_min_max_5.rs @@ -0,0 +1,405 @@ +#[test] +#[allow(non_snake_case)] +fn multiline_min_max_5__border_box() { + #[allow(unused_imports)] + use taffy::{prelude::*, tree::Layout, TaffyTree}; + let mut taffy: TaffyTree = TaffyTree::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Length(600f32), + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) }, + max_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(300f32), height: auto() }, + ..Default::default() + }) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node2 = taffy + .new_leaf(taffy::style::Style { + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node3 = taffy + .new_leaf(taffy::style::Style { + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_wrap: taffy::style::FlexWrap::Wrap, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(600f32), + height: taffy::style::Dimension::Length(20f32), + }, + border: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Length(5f32), + right: taffy::style::LengthPercentage::Length(5f32), + top: taffy::style::LengthPercentage::Length(5f32), + bottom: taffy::style::LengthPercentage::Length(5f32), + }, + ..Default::default() + }, + &[node0, node1, node2, node3], + ) + .unwrap(); + taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap(); + println!("\nComputed tree:"); + taffy.print_tree(node); + println!(); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 610f32, "width of node {:?}. Expected {}. Actual {}", node, 610f32, size.width); + assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, 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); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node0, 300f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height); + assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node0, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node0, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height); + assert_eq!(location.x, 305f32, "x of node {:?}. Expected {}. Actual {}", node1, 305f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node1, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node1, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node1, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height); + assert_eq!(location.x, 405f32, "x of node {:?}. Expected {}. Actual {}", node2, 405f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node2, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node2, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node2, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node3, 100f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height); + assert_eq!(location.x, 505f32, "x of node {:?}. Expected {}. Actual {}", node3, 505f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node3, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node3, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node3, + 0f32, + layout.scroll_height() + ); +} + +#[test] +#[allow(non_snake_case)] +fn multiline_min_max_5__content_box() { + #[allow(unused_imports)] + use taffy::{prelude::*, tree::Layout, TaffyTree}; + let mut taffy: TaffyTree = TaffyTree::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Length(600f32), + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) }, + max_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(300f32), height: auto() }, + ..Default::default() + }) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node2 = taffy + .new_leaf(taffy::style::Style { + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node3 = taffy + .new_leaf(taffy::style::Style { + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_wrap: taffy::style::FlexWrap::Wrap, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(600f32), + height: taffy::style::Dimension::Length(20f32), + }, + border: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Length(5f32), + right: taffy::style::LengthPercentage::Length(5f32), + top: taffy::style::LengthPercentage::Length(5f32), + bottom: taffy::style::LengthPercentage::Length(5f32), + }, + ..Default::default() + }, + &[node0, node1, node2, node3], + ) + .unwrap(); + taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap(); + println!("\nComputed tree:"); + taffy.print_tree(node); + println!(); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 610f32, "width of node {:?}. Expected {}. Actual {}", node, 610f32, size.width); + assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, 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); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node0, 300f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height); + assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node0, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node0, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height); + assert_eq!(location.x, 305f32, "x of node {:?}. Expected {}. Actual {}", node1, 305f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node1, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node1, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node1, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height); + assert_eq!(location.x, 405f32, "x of node {:?}. Expected {}. Actual {}", node2, 405f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node2, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node2, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node2, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node3, 100f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height); + assert_eq!(location.x, 505f32, "x of node {:?}. Expected {}. Actual {}", node3, 505f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node3, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node3, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node3, + 0f32, + layout.scroll_height() + ); +} diff --git a/tests/generated/flex/multiline_min_max_8.rs b/tests/generated/flex/multiline_min_max_8.rs new file mode 100644 index 000000000..12aedb5cd --- /dev/null +++ b/tests/generated/flex/multiline_min_max_8.rs @@ -0,0 +1,413 @@ +#[test] +#[allow(non_snake_case)] +fn multiline_min_max_8__border_box() { + #[allow(unused_imports)] + use taffy::{prelude::*, tree::Layout, TaffyTree}; + let mut taffy: TaffyTree = TaffyTree::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Length(600f32), + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) }, + max_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(300f32), height: auto() }, + margin: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Length(10f32), + right: zero(), + top: zero(), + bottom: zero(), + }, + ..Default::default() + }) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node2 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node3 = taffy + .new_leaf(taffy::style::Style { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_wrap: taffy::style::FlexWrap::Wrap, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(600f32), + height: taffy::style::Dimension::Length(20f32), + }, + border: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Length(5f32), + right: taffy::style::LengthPercentage::Length(5f32), + top: taffy::style::LengthPercentage::Length(5f32), + bottom: taffy::style::LengthPercentage::Length(5f32), + }, + ..Default::default() + }, + &[node0, node1, node2, node3], + ) + .unwrap(); + taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap(); + println!("\nComputed tree:"); + taffy.print_tree(node); + println!(); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 610f32, "width of node {:?}. Expected {}. Actual {}", node, 610f32, size.width); + assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, 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); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node0, 300f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height); + assert_eq!(location.x, 15f32, "x of node {:?}. Expected {}. Actual {}", node0, 15f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node0, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node0, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap(); + assert_eq!(size.width, 145f32, "width of node {:?}. Expected {}. Actual {}", node1, 145f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height); + assert_eq!(location.x, 315f32, "x of node {:?}. Expected {}. Actual {}", node1, 315f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node1, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node1, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node1, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap(); + assert_eq!(size.width, 145f32, "width of node {:?}. Expected {}. Actual {}", node2, 145f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height); + assert_eq!(location.x, 460f32, "x of node {:?}. Expected {}. Actual {}", node2, 460f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node2, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node2, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node2, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap(); + assert_eq!(size.width, 600f32, "width of node {:?}. Expected {}. Actual {}", node3, 600f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height); + assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node3, 5f32, location.x); + assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node3, 15f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node3, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node3, + 0f32, + layout.scroll_height() + ); +} + +#[test] +#[allow(non_snake_case)] +fn multiline_min_max_8__content_box() { + #[allow(unused_imports)] + use taffy::{prelude::*, tree::Layout, TaffyTree}; + let mut taffy: TaffyTree = TaffyTree::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Length(600f32), + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) }, + max_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(300f32), height: auto() }, + margin: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Length(10f32), + right: zero(), + top: zero(), + bottom: zero(), + }, + ..Default::default() + }) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node2 = taffy + .new_leaf(taffy::style::Style { + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node3 = taffy + .new_leaf(taffy::style::Style { + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Auto, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(100f32), + height: taffy::style::Dimension::Length(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + box_sizing: taffy::style::BoxSizing::ContentBox, + flex_wrap: taffy::style::FlexWrap::Wrap, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Length(600f32), + height: taffy::style::Dimension::Length(20f32), + }, + border: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Length(5f32), + right: taffy::style::LengthPercentage::Length(5f32), + top: taffy::style::LengthPercentage::Length(5f32), + bottom: taffy::style::LengthPercentage::Length(5f32), + }, + ..Default::default() + }, + &[node0, node1, node2, node3], + ) + .unwrap(); + taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap(); + println!("\nComputed tree:"); + taffy.print_tree(node); + println!(); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 610f32, "width of node {:?}. Expected {}. Actual {}", node, 610f32, size.width); + assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, 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); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node0, 300f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height); + assert_eq!(location.x, 15f32, "x of node {:?}. Expected {}. Actual {}", node0, 15f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node0, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node0, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap(); + assert_eq!(size.width, 145f32, "width of node {:?}. Expected {}. Actual {}", node1, 145f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height); + assert_eq!(location.x, 315f32, "x of node {:?}. Expected {}. Actual {}", node1, 315f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node1, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node1, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node1, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap(); + assert_eq!(size.width, 145f32, "width of node {:?}. Expected {}. Actual {}", node2, 145f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height); + assert_eq!(location.x, 460f32, "x of node {:?}. Expected {}. Actual {}", node2, 460f32, location.x); + assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node2, 5f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node2, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node2, + 0f32, + layout.scroll_height() + ); + #[cfg_attr(not(feature = "content_size"), allow(unused_variables))] + let layout @ Layout { size, location, .. } = taffy.layout(node3).unwrap(); + assert_eq!(size.width, 600f32, "width of node {:?}. Expected {}. Actual {}", node3, 600f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height); + assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node3, 5f32, location.x); + assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node3, 15f32, location.y); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_width(), + 0f32, + "scroll_width of node {:?}. Expected {}. Actual {}", + node3, + 0f32, + layout.scroll_width() + ); + #[cfg(feature = "content_size")] + assert_eq!( + layout.scroll_height(), + 0f32, + "scroll_height of node {:?}. Expected {}. Actual {}", + node3, + 0f32, + layout.scroll_height() + ); +}