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