⎇ 568f643327ec6b4879df0087def7f4e66b6acafb
tests/generated/simple_child.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Rename `Points`/`points` to `Length`/`length` in many APIs (#459)
1#[test]
2fn simple_child() {
3 #[allow(unused_imports)]
4 use taffy::{prelude::*, tree::Layout};
5 let mut taffy = taffy::Taffy::new();
6 let node000 = taffy
7 .new_leaf(taffy::style::Style {
8 size: taffy::geometry::Size {
9 width: taffy::style::Dimension::Length(10f32),
10 height: taffy::style::Dimension::Length(10f32),
11 },
12 ..Default::default()
13 })
14 .unwrap();
15 let node00 = taffy
16 .new_with_children(
17 taffy::style::Style {
18 size: taffy::geometry::Size {
19 width: taffy::style::Dimension::Length(10f32),
20 height: taffy::style::Dimension::Length(10f32),
21 },
22 ..Default::default()
23 },
24 &[node000],
25 )
26 .unwrap();
27 let node010 = taffy
28 .new_leaf(taffy::style::Style {
29 align_self: Some(taffy::style::AlignSelf::Center),
30 size: taffy::geometry::Size {
31 width: taffy::style::Dimension::Length(10f32),
32 height: taffy::style::Dimension::Length(10f32),
33 },
34 ..Default::default()
35 })
36 .unwrap();
37 let node011 = taffy
38 .new_leaf(taffy::style::Style {
39 align_self: Some(taffy::style::AlignSelf::Center),
40 size: taffy::geometry::Size {
41 width: taffy::style::Dimension::Length(10f32),
42 height: taffy::style::Dimension::Length(10f32),
43 },
44 ..Default::default()
45 })
46 .unwrap();
47 let node01 = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node010, node011]).unwrap();
48 let node0 = taffy
49 .new_with_children(
50 taffy::style::Style {
51 size: taffy::geometry::Size {
52 width: taffy::style::Dimension::Percent(1f32),
53 height: taffy::style::Dimension::Percent(1f32),
54 },
55 ..Default::default()
56 },
57 &[node00, node01],
58 )
59 .unwrap();
60 let node = taffy
61 .new_with_children(
62 taffy::style::Style {
63 size: taffy::geometry::Size {
64 width: taffy::style::Dimension::Length(100f32),
65 height: taffy::style::Dimension::Length(100f32),
66 },
67 ..Default::default()
68 },
69 &[node0],
70 )
71 .unwrap();
72 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
73 println!("\nComputed tree:");
74 taffy::util::print_tree(&taffy, node);
75 println!();
76 let Layout { size, location, .. } = taffy.layout(node).unwrap();
77 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
78 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
79 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
80 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
81 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
82 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
83 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
84 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
85 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
86 let Layout { size, location, .. } = taffy.layout(node00).unwrap();
87 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node00, 10f32, size.width);
88 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00, 10f32, size.height);
89 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
90 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
91 let Layout { size, location, .. } = taffy.layout(node000).unwrap();
92 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node000, 10f32, size.width);
93 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node000, 10f32, size.height);
94 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000, 0f32, location.x);
95 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node000, 0f32, location.y);
96 let Layout { size, location, .. } = taffy.layout(node01).unwrap();
97 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node01, 20f32, size.width);
98 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node01, 100f32, size.height);
99 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node01, 10f32, location.x);
100 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node01, 0f32, location.y);
101 let Layout { size, location, .. } = taffy.layout(node010).unwrap();
102 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node010, 10f32, size.width);
103 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node010, 10f32, size.height);
104 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node010, 0f32, location.x);
105 assert_eq!(location.y, 45f32, "y of node {:?}. Expected {}. Actual {}", node010, 45f32, location.y);
106 let Layout { size, location, .. } = taffy.layout(node011).unwrap();
107 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node011, 10f32, size.width);
108 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node011, 10f32, size.height);
109 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node011, 10f32, location.x);
110 assert_eq!(location.y, 45f32, "y of node {:?}. Expected {}. Actual {}", node011, 45f32, location.y);
111}