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