#[test] #[allow(non_snake_case)] fn bevy_issue_9530__border_box() { #[allow(unused_imports)] use taffy::{prelude::*, Layout}; let mut taffy = crate::new_test_tree(); let node0 = taffy .new_leaf(taffy::style::Style { flex_direction: taffy::style::FlexDirection::Column, size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(1f32), height: taffy::style::Dimension::from_length(20f32), }, ..Default::default() }) .unwrap(); let node10 = taffy .new_leaf(taffy::style::Style { size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(1f32), height: taffy::style::Dimension::from_length(50f32), }, ..Default::default() }) .unwrap(); let node11 = taffy . new_leaf_with_context (taffy :: style :: Style { align_items : Some (taffy :: style :: AlignItems :: Center) , align_content : Some (taffy :: style :: AlignContent :: Center) , justify_content : Some (taffy :: style :: JustifyContent :: Center) , flex_grow : 1f32 , margin : taffy :: geometry :: Rect { left : length (20f32) , right : length (20f32) , top : length (20f32) , bottom : length (20f32) , } , .. Default :: default () } , crate :: TestNodeContext :: ahem_text ("HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH" , crate :: WritingMode :: Horizontal) ,) . unwrap () ; let node12 = taffy .new_leaf(taffy::style::Style { size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(1f32), height: taffy::style::Dimension::from_length(50f32), }, ..Default::default() }) .unwrap(); let node1 = taffy .new_with_children( taffy::style::Style { flex_direction: taffy::style::FlexDirection::Column, flex_grow: 1f32, size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(1f32), height: auto() }, margin: taffy::geometry::Rect { left: length(20f32), right: length(20f32), top: length(20f32), bottom: length(20f32), }, padding: taffy::geometry::Rect { left: length(20f32), right: length(20f32), top: length(20f32), bottom: length(20f32), }, ..Default::default() }, &[node10, node11, node12], ) .unwrap(); let node = taffy .new_with_children( taffy::style::Style { flex_direction: taffy::style::FlexDirection::Column, align_items: Some(taffy::style::AlignItems::Center), align_content: Some(taffy::style::AlignContent::Center), size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(300f32), height: taffy::style::Dimension::from_length(300f32), }, margin: taffy::geometry::Rect { left: taffy::style::LengthPercentageAuto::AUTO, right: taffy::style::LengthPercentageAuto::AUTO, top: taffy::style::LengthPercentageAuto::AUTO, bottom: taffy::style::LengthPercentageAuto::AUTO, }, ..Default::default() }, &[node0, node1], ) .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!(); let layout = taffy.layout(node).unwrap(); let Layout { size, location, .. } = layout; assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node, 300f32, 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 = taffy.layout(node0).unwrap(); let Layout { size, location, .. } = layout; assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node0, 300f32, size.width); assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node0, 0f32, 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 = taffy.layout(node1).unwrap(); let Layout { size, location, .. } = layout; assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node1, 300f32, size.width); assert_eq!(size.height, 420f32, "height of node {:?}. Expected {}. Actual {}", node1, 420f32, size.height); assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x); assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node1, 20f32, location.y); let layout = taffy.layout(node10).unwrap(); let Layout { size, location, .. } = layout; assert_eq!(size.width, 260f32, "width of node {:?}. Expected {}. Actual {}", node10, 260f32, size.width); assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node10, 50f32, size.height); assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node10, 20f32, location.x); assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node10, 20f32, location.y); let layout = taffy.layout(node11).unwrap(); let Layout { size, location, .. } = layout; assert_eq!(size.width, 220f32, "width of node {:?}. Expected {}. Actual {}", node11, 220f32, size.width); assert_eq!(size.height, 240f32, "height of node {:?}. Expected {}. Actual {}", node11, 240f32, size.height); assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node11, 40f32, location.x); assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node11, 90f32, location.y); let layout = taffy.layout(node12).unwrap(); let Layout { size, location, .. } = layout; assert_eq!(size.width, 260f32, "width of node {:?}. Expected {}. Actual {}", node12, 260f32, size.width); assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node12, 50f32, size.height); assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node12, 20f32, location.x); assert_eq!(location.y, 350f32, "y of node {:?}. Expected {}. Actual {}", node12, 350f32, location.y); } #[test] #[allow(non_snake_case)] fn bevy_issue_9530__content_box() { #[allow(unused_imports)] use taffy::{prelude::*, Layout}; let mut taffy = crate::new_test_tree(); let node0 = taffy .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, flex_direction: taffy::style::FlexDirection::Column, size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(1f32), height: taffy::style::Dimension::from_length(20f32), }, ..Default::default() }) .unwrap(); let node10 = taffy .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(1f32), height: taffy::style::Dimension::from_length(50f32), }, ..Default::default() }) .unwrap(); let node11 = taffy . new_leaf_with_context (taffy :: style :: Style { box_sizing : taffy :: style :: BoxSizing :: ContentBox , align_items : Some (taffy :: style :: AlignItems :: Center) , align_content : Some (taffy :: style :: AlignContent :: Center) , justify_content : Some (taffy :: style :: JustifyContent :: Center) , flex_grow : 1f32 , margin : taffy :: geometry :: Rect { left : length (20f32) , right : length (20f32) , top : length (20f32) , bottom : length (20f32) , } , .. Default :: default () } , crate :: TestNodeContext :: ahem_text ("HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH" , crate :: WritingMode :: Horizontal) ,) . unwrap () ; let node12 = taffy .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(1f32), height: taffy::style::Dimension::from_length(50f32), }, ..Default::default() }) .unwrap(); let node1 = taffy .new_with_children( taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, flex_direction: taffy::style::FlexDirection::Column, flex_grow: 1f32, size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(1f32), height: auto() }, margin: taffy::geometry::Rect { left: length(20f32), right: length(20f32), top: length(20f32), bottom: length(20f32), }, padding: taffy::geometry::Rect { left: length(20f32), right: length(20f32), top: length(20f32), bottom: length(20f32), }, ..Default::default() }, &[node10, node11, node12], ) .unwrap(); let node = taffy .new_with_children( taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, flex_direction: taffy::style::FlexDirection::Column, align_items: Some(taffy::style::AlignItems::Center), align_content: Some(taffy::style::AlignContent::Center), size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(300f32), height: taffy::style::Dimension::from_length(300f32), }, margin: taffy::geometry::Rect { left: taffy::style::LengthPercentageAuto::AUTO, right: taffy::style::LengthPercentageAuto::AUTO, top: taffy::style::LengthPercentageAuto::AUTO, bottom: taffy::style::LengthPercentageAuto::AUTO, }, ..Default::default() }, &[node0, node1], ) .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!(); let layout = taffy.layout(node).unwrap(); let Layout { size, location, .. } = layout; assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node, 300f32, 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 = taffy.layout(node0).unwrap(); let Layout { size, location, .. } = layout; assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node0, 300f32, size.width); assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node0, 0f32, 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 = taffy.layout(node1).unwrap(); let Layout { size, location, .. } = layout; assert_eq!(size.width, 340f32, "width of node {:?}. Expected {}. Actual {}", node1, 340f32, size.width); assert_eq!(size.height, 380f32, "height of node {:?}. Expected {}. Actual {}", node1, 380f32, size.height); assert_eq!(location.x, -20f32, "x of node {:?}. Expected {}. Actual {}", node1, -20f32, location.x); assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node1, 20f32, location.y); let layout = taffy.layout(node10).unwrap(); let Layout { size, location, .. } = layout; assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node10, 300f32, size.width); assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node10, 50f32, size.height); assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node10, 20f32, location.x); assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node10, 20f32, location.y); let layout = taffy.layout(node11).unwrap(); let Layout { size, location, .. } = layout; assert_eq!(size.width, 260f32, "width of node {:?}. Expected {}. Actual {}", node11, 260f32, size.width); assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node11, 200f32, size.height); assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node11, 40f32, location.x); assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node11, 90f32, location.y); let layout = taffy.layout(node12).unwrap(); let Layout { size, location, .. } = layout; assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node12, 300f32, size.width); assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node12, 50f32, size.height); assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node12, 20f32, location.x); assert_eq!(location.y, 310f32, "y of node {:?}. Expected {}. Actual {}", node12, 310f32, location.y); }