Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn blockgrid_grid_in_block__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node00 = 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 ..Default::default()
14 })
15 .unwrap();
16 let node0 = taffy
17 .new_with_children(
18 taffy::style::Style { display: taffy::style::Display::Grid, ..Default::default() },
19 &[node00],
20 )
21 .unwrap();
22 let node1 = taffy
23 .new_leaf(taffy::style::Style {
24 display: taffy::style::Display::Block,
25 size: taffy::geometry::Size {
26 width: taffy::style::Dimension::from_length(50f32),
27 height: taffy::style::Dimension::from_length(20f32),
28 },
29 ..Default::default()
30 })
31 .unwrap();
32 let node = taffy
33 .new_with_children(
34 taffy::style::Style {
35 display: taffy::style::Display::Block,
36 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(200f32), height: auto() },
37 ..Default::default()
38 },
39 &[node0, node1],
40 )
41 .unwrap();
42 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
43 println!("\nComputed tree:");
44 taffy.print_tree(node);
45 println!();
46 let layout = taffy.layout(node).unwrap();
47 let Layout { size, location, .. } = layout;
48 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
49 assert_eq!(size.height, 70f32, "height of node {:?}. Expected {}. Actual {}", node, 70f32, size.height);
50 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
51 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
52 let layout = taffy.layout(node0).unwrap();
53 let Layout { size, location, .. } = layout;
54 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
55 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
56 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
57 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
58 let layout = taffy.layout(node00).unwrap();
59 let Layout { size, location, .. } = layout;
60 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
61 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node00, 50f32, size.height);
62 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
63 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
64 let layout = taffy.layout(node1).unwrap();
65 let Layout { size, location, .. } = layout;
66 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
67 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
68 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
69 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node1, 50f32, location.y);
70}
71
72#[test]
73#[allow(non_snake_case)]
74fn blockgrid_grid_in_block__content_box() {
75 #[allow(unused_imports)]
76 use taffy::{prelude::*, Layout};
77 let mut taffy = crate::new_test_tree();
78 let node00 = taffy
79 .new_leaf(taffy::style::Style {
80 box_sizing: taffy::style::BoxSizing::ContentBox,
81 size: taffy::geometry::Size {
82 width: taffy::style::Dimension::from_length(50f32),
83 height: taffy::style::Dimension::from_length(50f32),
84 },
85 ..Default::default()
86 })
87 .unwrap();
88 let node0 = taffy
89 .new_with_children(
90 taffy::style::Style {
91 display: taffy::style::Display::Grid,
92 box_sizing: taffy::style::BoxSizing::ContentBox,
93 ..Default::default()
94 },
95 &[node00],
96 )
97 .unwrap();
98 let node1 = taffy
99 .new_leaf(taffy::style::Style {
100 display: taffy::style::Display::Block,
101 box_sizing: taffy::style::BoxSizing::ContentBox,
102 size: taffy::geometry::Size {
103 width: taffy::style::Dimension::from_length(50f32),
104 height: taffy::style::Dimension::from_length(20f32),
105 },
106 ..Default::default()
107 })
108 .unwrap();
109 let node = taffy
110 .new_with_children(
111 taffy::style::Style {
112 display: taffy::style::Display::Block,
113 box_sizing: taffy::style::BoxSizing::ContentBox,
114 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(200f32), height: auto() },
115 ..Default::default()
116 },
117 &[node0, node1],
118 )
119 .unwrap();
120 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
121 println!("\nComputed tree:");
122 taffy.print_tree(node);
123 println!();
124 let layout = taffy.layout(node).unwrap();
125 let Layout { size, location, .. } = layout;
126 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
127 assert_eq!(size.height, 70f32, "height of node {:?}. Expected {}. Actual {}", node, 70f32, size.height);
128 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
129 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
130 let layout = taffy.layout(node0).unwrap();
131 let Layout { size, location, .. } = layout;
132 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
133 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
134 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
135 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
136 let layout = taffy.layout(node00).unwrap();
137 let Layout { size, location, .. } = layout;
138 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
139 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node00, 50f32, size.height);
140 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
141 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
142 let layout = taffy.layout(node1).unwrap();
143 let Layout { size, location, .. } = layout;
144 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
145 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
146 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
147 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node1, 50f32, location.y);
148}