Update 0.3.x for 0.3.11 (#455)
1#[test]
2fn bevy_issue_7976_3_level() {
3 use slotmap::Key;
4 #[allow(unused_imports)]
5 use taffy::{layout::Layout, prelude::*};
6 let mut taffy = taffy::Taffy::new();
7 let node00 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::Percent(1f32),
11 height: taffy::style::Dimension::Percent(1f32),
12 },
13 padding: taffy::geometry::Rect {
14 left: taffy::style::LengthPercentage::Points(5f32),
15 right: taffy::style::LengthPercentage::Points(5f32),
16 top: taffy::style::LengthPercentage::Points(5f32),
17 bottom: taffy::style::LengthPercentage::Points(5f32),
18 },
19 ..Default::default()
20 })
21 .unwrap();
22 let node0 = taffy
23 .new_with_children(
24 taffy::style::Style {
25 min_size: taffy::geometry::Size {
26 width: taffy::style::Dimension::Points(40f32),
27 height: taffy::style::Dimension::Points(40f32),
28 },
29 margin: taffy::geometry::Rect {
30 left: taffy::style::LengthPercentageAuto::Points(5f32),
31 right: taffy::style::LengthPercentageAuto::Points(5f32),
32 top: taffy::style::LengthPercentageAuto::Points(5f32),
33 bottom: taffy::style::LengthPercentageAuto::Points(5f32),
34 },
35 padding: taffy::geometry::Rect {
36 left: taffy::style::LengthPercentage::Points(5f32),
37 right: taffy::style::LengthPercentage::Points(5f32),
38 top: taffy::style::LengthPercentage::Points(5f32),
39 bottom: taffy::style::LengthPercentage::Points(5f32),
40 },
41 ..Default::default()
42 },
43 &[node00],
44 )
45 .unwrap();
46 let node = taffy
47 .new_with_children(
48 taffy::style::Style {
49 align_content: Some(taffy::style::AlignContent::Start),
50 size: taffy::geometry::Size {
51 width: taffy::style::Dimension::Points(200f32),
52 height: taffy::style::Dimension::Points(200f32),
53 },
54 ..Default::default()
55 },
56 &[node0],
57 )
58 .unwrap();
59 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
60 println!("\nComputed tree:");
61 taffy::debug::print_tree(&taffy, node);
62 println!();
63 let Layout { size, location, .. } = taffy.layout(node).unwrap();
64 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.width);
65 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.height);
66 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
67 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
68 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
69 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width);
70 assert_eq!(size.height, 190f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 190f32, size.height);
71 assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 5f32, location.x);
72 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 5f32, location.y);
73 let Layout { size, location, .. } = taffy.layout(node00).unwrap();
74 assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 30f32, size.width);
75 assert_eq!(size.height, 180f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 180f32, size.height);
76 assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 5f32, location.x);
77 assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 5f32, location.y);
78}