⎇ float-layout
tests/generated/block/block_margin_auto_bottom_and_top.rs
History
Who touched what
raw
Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn block_margin_auto_bottom_and_top__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: taffy::style::LengthPercentageAuto::AUTO,
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 ..Default::default()
29 })
30 .unwrap();
31 let node = taffy
32 .new_with_children(
33 taffy::style::Style {
34 display: taffy::style::Display::Block,
35 size: taffy::geometry::Size {
36 width: taffy::style::Dimension::from_length(200f32),
37 height: taffy::style::Dimension::from_length(200f32),
38 },
39 ..Default::default()
40 },
41 &[node0, node1],
42 )
43 .unwrap();
44 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
45 println!("\nComputed tree:");
46 taffy.print_tree(node);
47 println!();
48 let layout = taffy.layout(node).unwrap();
49 let Layout { size, location, .. } = layout;
50 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
51 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
52 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
53 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
54 let layout = taffy.layout(node0).unwrap();
55 let Layout { size, location, .. } = layout;
56 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
57 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
58 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
59 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
60 let layout = taffy.layout(node1).unwrap();
61 let Layout { size, location, .. } = layout;
62 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
63 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
64 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
65 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node1, 50f32, location.y);
66}
67
68#[test]
69#[allow(non_snake_case)]
70fn block_margin_auto_bottom_and_top__content_box() {
71 #[allow(unused_imports)]
72 use taffy::{prelude::*, Layout};
73 let mut taffy = crate::new_test_tree();
74 let node0 = taffy
75 .new_leaf(taffy::style::Style {
76 box_sizing: taffy::style::BoxSizing::ContentBox,
77 size: taffy::geometry::Size {
78 width: taffy::style::Dimension::from_length(50f32),
79 height: taffy::style::Dimension::from_length(50f32),
80 },
81 margin: taffy::geometry::Rect {
82 left: zero(),
83 right: zero(),
84 top: taffy::style::LengthPercentageAuto::AUTO,
85 bottom: taffy::style::LengthPercentageAuto::AUTO,
86 },
87 ..Default::default()
88 })
89 .unwrap();
90 let node1 = taffy
91 .new_leaf(taffy::style::Style {
92 box_sizing: taffy::style::BoxSizing::ContentBox,
93 size: taffy::geometry::Size {
94 width: taffy::style::Dimension::from_length(50f32),
95 height: taffy::style::Dimension::from_length(50f32),
96 },
97 ..Default::default()
98 })
99 .unwrap();
100 let node = taffy
101 .new_with_children(
102 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(200f32),
107 height: taffy::style::Dimension::from_length(200f32),
108 },
109 ..Default::default()
110 },
111 &[node0, node1],
112 )
113 .unwrap();
114 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
115 println!("\nComputed tree:");
116 taffy.print_tree(node);
117 println!();
118 let layout = taffy.layout(node).unwrap();
119 let Layout { size, location, .. } = layout;
120 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
121 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
122 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
123 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
124 let layout = taffy.layout(node0).unwrap();
125 let Layout { size, location, .. } = layout;
126 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
127 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
128 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
129 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
130 let layout = taffy.layout(node1).unwrap();
131 let Layout { size, location, .. } = layout;
132 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
133 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
134 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
135 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node1, 50f32, location.y);
136}