#[test] fn bevy_issue_8017() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; let mut taffy = taffy::Taffy::new(); let node00 = taffy .new_leaf(taffy::style::Style { size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(1f32), height: taffy::style::Dimension::Percent(1f32), }, ..Default::default() }) .unwrap(); let node01 = taffy .new_leaf(taffy::style::Style { size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(1f32), height: taffy::style::Dimension::Percent(1f32), }, ..Default::default() }) .unwrap(); let node0 = taffy .new_with_children( taffy::style::Style { display: taffy::style::Display::Flex, gap: taffy::geometry::Size { width: taffy::style::LengthPercentage::Points(8f32), height: taffy::style::LengthPercentage::Points(8f32), }, size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(1f32), height: taffy::style::Dimension::Percent(0.5f32), }, ..Default::default() }, &[node00, node01], ) .unwrap(); let node10 = taffy .new_leaf(taffy::style::Style { size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(1f32), height: taffy::style::Dimension::Percent(1f32), }, ..Default::default() }) .unwrap(); let node11 = taffy .new_leaf(taffy::style::Style { size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(1f32), height: taffy::style::Dimension::Percent(1f32), }, ..Default::default() }) .unwrap(); let node1 = taffy .new_with_children( taffy::style::Style { display: taffy::style::Display::Flex, gap: taffy::geometry::Size { width: taffy::style::LengthPercentage::Points(8f32), height: taffy::style::LengthPercentage::Points(8f32), }, size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(1f32), height: taffy::style::Dimension::Percent(0.5f32), }, ..Default::default() }, &[node10, node11], ) .unwrap(); let node = taffy .new_with_children( taffy::style::Style { display: taffy::style::Display::Flex, flex_direction: taffy::style::FlexDirection::Column, gap: taffy::geometry::Size { width: taffy::style::LengthPercentage::Points(8f32), height: taffy::style::LengthPercentage::Points(8f32), }, size: taffy::geometry::Size { width: taffy::style::Dimension::Points(400f32), height: taffy::style::Dimension::Points(400f32), }, padding: taffy::geometry::Rect { left: taffy::style::LengthPercentage::Points(8f32), right: taffy::style::LengthPercentage::Points(8f32), top: taffy::style::LengthPercentage::Points(8f32), bottom: taffy::style::LengthPercentage::Points(8f32), }, ..Default::default() }, &[node0, node1], ) .unwrap(); taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); println!("\nComputed tree:"); taffy::debug::print_tree(&taffy, node); println!(); let Layout { size, location, .. } = taffy.layout(node).unwrap(); assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 400f32, size.width); assert_eq!(size.height, 400f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 400f32, size.height); assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); let Layout { size, location, .. } = taffy.layout(node0).unwrap(); assert_eq!(size.width, 384f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 384f32, size.width); assert_eq!(size.height, 188f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 188f32, size.height); assert_eq!(location.x, 8f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 8f32, location.x); assert_eq!(location.y, 8f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 8f32, location.y); let Layout { size, location, .. } = taffy.layout(node00).unwrap(); assert_eq!(size.width, 188f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 188f32, size.width); assert_eq!(size.height, 188f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 188f32, size.height); assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x); assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.y); let Layout { size, location, .. } = taffy.layout(node01).unwrap(); assert_eq!(size.width, 188f32, "width of node {:?}. Expected {}. Actual {}", node01.data(), 188f32, size.width); assert_eq!(size.height, 188f32, "height of node {:?}. Expected {}. Actual {}", node01.data(), 188f32, size.height); assert_eq!(location.x, 196f32, "x of node {:?}. Expected {}. Actual {}", node01.data(), 196f32, location.x); assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01.data(), 0f32, location.y); let Layout { size, location, .. } = taffy.layout(node1).unwrap(); assert_eq!(size.width, 384f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 384f32, size.width); assert_eq!(size.height, 188f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 188f32, size.height); assert_eq!(location.x, 8f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 8f32, location.x); assert_eq!(location.y, 204f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 204f32, location.y); let Layout { size, location, .. } = taffy.layout(node10).unwrap(); assert_eq!(size.width, 188f32, "width of node {:?}. Expected {}. Actual {}", node10.data(), 188f32, size.width); assert_eq!(size.height, 188f32, "height of node {:?}. Expected {}. Actual {}", node10.data(), 188f32, size.height); assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.x); assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10.data(), 0f32, location.y); let Layout { size, location, .. } = taffy.layout(node11).unwrap(); assert_eq!(size.width, 188f32, "width of node {:?}. Expected {}. Actual {}", node11.data(), 188f32, size.width); assert_eq!(size.height, 188f32, "height of node {:?}. Expected {}. Actual {}", node11.data(), 188f32, size.height); assert_eq!(location.x, 196f32, "x of node {:?}. Expected {}. Actual {}", node11.data(), 196f32, location.x); assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node11.data(), 0f32, location.y); }