⎇ float-layout
tests/generated/flex/margin_auto_multiple_children_column.rs
Historia
Quién tocó qué
crudo
Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn margin_auto_multiple_children_column__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node0 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::from_length(50f32),
11 height: taffy::style::Dimension::from_length(50f32),
12 },
13 margin: taffy::geometry::Rect {
14 left: zero(),
15 right: zero(),
16 top: taffy::style::LengthPercentageAuto::AUTO,
17 bottom: zero(),
18 },
19 ..Default::default()
20 })
21 .unwrap();
22 let node1 = taffy
23 .new_leaf(taffy::style::Style {
24 size: taffy::geometry::Size {
25 width: taffy::style::Dimension::from_length(50f32),
26 height: taffy::style::Dimension::from_length(50f32),
27 },
28 margin: taffy::geometry::Rect {
29 left: zero(),
30 right: zero(),
31 top: taffy::style::LengthPercentageAuto::AUTO,
32 bottom: zero(),
33 },
34 ..Default::default()
35 })
36 .unwrap();
37 let node2 = taffy
38 .new_leaf(taffy::style::Style {
39 size: taffy::geometry::Size {
40 width: taffy::style::Dimension::from_length(50f32),
41 height: taffy::style::Dimension::from_length(50f32),
42 },
43 ..Default::default()
44 })
45 .unwrap();
46 let node = taffy
47 .new_with_children(
48 taffy::style::Style {
49 flex_direction: taffy::style::FlexDirection::Column,
50 align_items: Some(taffy::style::AlignItems::Center),
51 size: taffy::geometry::Size {
52 width: taffy::style::Dimension::from_length(200f32),
53 height: taffy::style::Dimension::from_length(200f32),
54 },
55 ..Default::default()
56 },
57 &[node0, node1, node2],
58 )
59 .unwrap();
60 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
61 println!("\nComputed tree:");
62 taffy.print_tree(node);
63 println!();
64 let layout = taffy.layout(node).unwrap();
65 let Layout { size, location, .. } = layout;
66 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
67 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
68 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
69 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
70 let layout = taffy.layout(node0).unwrap();
71 let Layout { size, location, .. } = layout;
72 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
73 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
74 assert_eq!(location.x, 75f32, "x of node {:?}. Expected {}. Actual {}", node0, 75f32, location.x);
75 assert_eq!(location.y, 25f32, "y of node {:?}. Expected {}. Actual {}", node0, 25f32, location.y);
76 let layout = taffy.layout(node1).unwrap();
77 let Layout { size, location, .. } = layout;
78 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
79 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
80 assert_eq!(location.x, 75f32, "x of node {:?}. Expected {}. Actual {}", node1, 75f32, location.x);
81 assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node1, 100f32, location.y);
82 let layout = taffy.layout(node2).unwrap();
83 let Layout { size, location, .. } = layout;
84 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
85 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2, 50f32, size.height);
86 assert_eq!(location.x, 75f32, "x of node {:?}. Expected {}. Actual {}", node2, 75f32, location.x);
87 assert_eq!(location.y, 150f32, "y of node {:?}. Expected {}. Actual {}", node2, 150f32, location.y);
88}
89
90#[test]
91#[allow(non_snake_case)]
92fn margin_auto_multiple_children_column__content_box() {
93 #[allow(unused_imports)]
94 use taffy::{prelude::*, Layout};
95 let mut taffy = crate::new_test_tree();
96 let node0 = taffy
97 .new_leaf(taffy::style::Style {
98 box_sizing: taffy::style::BoxSizing::ContentBox,
99 size: taffy::geometry::Size {
100 width: taffy::style::Dimension::from_length(50f32),
101 height: taffy::style::Dimension::from_length(50f32),
102 },
103 margin: taffy::geometry::Rect {
104 left: zero(),
105 right: zero(),
106 top: taffy::style::LengthPercentageAuto::AUTO,
107 bottom: zero(),
108 },
109 ..Default::default()
110 })
111 .unwrap();
112 let node1 = taffy
113 .new_leaf(taffy::style::Style {
114 box_sizing: taffy::style::BoxSizing::ContentBox,
115 size: taffy::geometry::Size {
116 width: taffy::style::Dimension::from_length(50f32),
117 height: taffy::style::Dimension::from_length(50f32),
118 },
119 margin: taffy::geometry::Rect {
120 left: zero(),
121 right: zero(),
122 top: taffy::style::LengthPercentageAuto::AUTO,
123 bottom: zero(),
124 },
125 ..Default::default()
126 })
127 .unwrap();
128 let node2 = taffy
129 .new_leaf(taffy::style::Style {
130 box_sizing: taffy::style::BoxSizing::ContentBox,
131 size: taffy::geometry::Size {
132 width: taffy::style::Dimension::from_length(50f32),
133 height: taffy::style::Dimension::from_length(50f32),
134 },
135 ..Default::default()
136 })
137 .unwrap();
138 let node = taffy
139 .new_with_children(
140 taffy::style::Style {
141 box_sizing: taffy::style::BoxSizing::ContentBox,
142 flex_direction: taffy::style::FlexDirection::Column,
143 align_items: Some(taffy::style::AlignItems::Center),
144 size: taffy::geometry::Size {
145 width: taffy::style::Dimension::from_length(200f32),
146 height: taffy::style::Dimension::from_length(200f32),
147 },
148 ..Default::default()
149 },
150 &[node0, node1, node2],
151 )
152 .unwrap();
153 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
154 println!("\nComputed tree:");
155 taffy.print_tree(node);
156 println!();
157 let layout = taffy.layout(node).unwrap();
158 let Layout { size, location, .. } = layout;
159 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
160 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
161 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
162 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
163 let layout = taffy.layout(node0).unwrap();
164 let Layout { size, location, .. } = layout;
165 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
166 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
167 assert_eq!(location.x, 75f32, "x of node {:?}. Expected {}. Actual {}", node0, 75f32, location.x);
168 assert_eq!(location.y, 25f32, "y of node {:?}. Expected {}. Actual {}", node0, 25f32, location.y);
169 let layout = taffy.layout(node1).unwrap();
170 let Layout { size, location, .. } = layout;
171 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
172 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
173 assert_eq!(location.x, 75f32, "x of node {:?}. Expected {}. Actual {}", node1, 75f32, location.x);
174 assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node1, 100f32, location.y);
175 let layout = taffy.layout(node2).unwrap();
176 let Layout { size, location, .. } = layout;
177 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
178 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2, 50f32, size.height);
179 assert_eq!(location.x, 75f32, "x of node {:?}. Expected {}. Actual {}", node2, 75f32, location.x);
180 assert_eq!(location.y, 150f32, "y of node {:?}. Expected {}. Actual {}", node2, 150f32, location.y);
181}