Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn grid_taffy_issue_624__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 grid_row: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Span(2u16) },
10 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
11 size: taffy::geometry::Size {
12 width: taffy::style::Dimension::from_length(100f32),
13 height: taffy::style::Dimension::from_length(50f32),
14 },
15 ..Default::default()
16 })
17 .unwrap();
18 let node1 = taffy
19 .new_leaf(taffy::style::Style {
20 grid_row: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Span(2u16) },
21 grid_column: taffy::geometry::Line { start: line(2i16), end: taffy::style::GridPlacement::Span(2u16) },
22 size: taffy::geometry::Size {
23 width: taffy::style::Dimension::from_length(40f32),
24 height: taffy::style::Dimension::from_length(30f32),
25 },
26 ..Default::default()
27 })
28 .unwrap();
29 let node2 = taffy
30 .new_leaf(taffy::style::Style {
31 grid_row: taffy::geometry::Line { start: line(3i16), end: taffy::style::GridPlacement::Span(1u16) },
32 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Span(2u16) },
33 size: taffy::geometry::Size {
34 width: taffy::style::Dimension::from_length(120f32),
35 height: taffy::style::Dimension::from_length(20f32),
36 },
37 ..Default::default()
38 })
39 .unwrap();
40 let node = taffy
41 .new_with_children(
42 taffy::style::Style {
43 display: taffy::style::Display::Grid,
44 justify_items: Some(taffy::style::JustifyItems::Start),
45 justify_content: Some(taffy::style::JustifyContent::Start),
46 grid_template_rows: vec![auto(), auto(), auto(), fr(1f32)],
47 grid_template_columns: vec![auto(), auto(), fr(1f32)],
48 size: taffy::geometry::Size {
49 width: taffy::style::Dimension::from_length(320f32),
50 height: taffy::style::Dimension::from_length(640f32),
51 },
52 ..Default::default()
53 },
54 &[node0, node1, node2],
55 )
56 .unwrap();
57 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
58 println!("\nComputed tree:");
59 taffy.print_tree(node);
60 println!();
61 let layout = taffy.layout(node).unwrap();
62 let Layout { size, location, .. } = layout;
63 assert_eq!(size.width, 320f32, "width of node {:?}. Expected {}. Actual {}", node, 320f32, size.width);
64 assert_eq!(size.height, 640f32, "height of node {:?}. Expected {}. Actual {}", node, 640f32, size.height);
65 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
66 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
67 let layout = taffy.layout(node0).unwrap();
68 let Layout { size, location, .. } = layout;
69 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
70 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
71 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
72 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
73 let layout = taffy.layout(node1).unwrap();
74 let Layout { size, location, .. } = layout;
75 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
76 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node1, 30f32, size.height);
77 assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node1, 100f32, location.x);
78 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
79 let layout = taffy.layout(node2).unwrap();
80 let Layout { size, location, .. } = layout;
81 assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node2, 120f32, size.width);
82 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
83 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
84 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node2, 50f32, location.y);
85}
86
87#[test]
88#[allow(non_snake_case)]
89fn grid_taffy_issue_624__content_box() {
90 #[allow(unused_imports)]
91 use taffy::{prelude::*, Layout};
92 let mut taffy = crate::new_test_tree();
93 let node0 = taffy
94 .new_leaf(taffy::style::Style {
95 box_sizing: taffy::style::BoxSizing::ContentBox,
96 grid_row: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Span(2u16) },
97 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
98 size: taffy::geometry::Size {
99 width: taffy::style::Dimension::from_length(100f32),
100 height: taffy::style::Dimension::from_length(50f32),
101 },
102 ..Default::default()
103 })
104 .unwrap();
105 let node1 = taffy
106 .new_leaf(taffy::style::Style {
107 box_sizing: taffy::style::BoxSizing::ContentBox,
108 grid_row: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Span(2u16) },
109 grid_column: taffy::geometry::Line { start: line(2i16), end: taffy::style::GridPlacement::Span(2u16) },
110 size: taffy::geometry::Size {
111 width: taffy::style::Dimension::from_length(40f32),
112 height: taffy::style::Dimension::from_length(30f32),
113 },
114 ..Default::default()
115 })
116 .unwrap();
117 let node2 = taffy
118 .new_leaf(taffy::style::Style {
119 box_sizing: taffy::style::BoxSizing::ContentBox,
120 grid_row: taffy::geometry::Line { start: line(3i16), end: taffy::style::GridPlacement::Span(1u16) },
121 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Span(2u16) },
122 size: taffy::geometry::Size {
123 width: taffy::style::Dimension::from_length(120f32),
124 height: taffy::style::Dimension::from_length(20f32),
125 },
126 ..Default::default()
127 })
128 .unwrap();
129 let node = taffy
130 .new_with_children(
131 taffy::style::Style {
132 display: taffy::style::Display::Grid,
133 box_sizing: taffy::style::BoxSizing::ContentBox,
134 justify_items: Some(taffy::style::JustifyItems::Start),
135 justify_content: Some(taffy::style::JustifyContent::Start),
136 grid_template_rows: vec![auto(), auto(), auto(), fr(1f32)],
137 grid_template_columns: vec![auto(), auto(), fr(1f32)],
138 size: taffy::geometry::Size {
139 width: taffy::style::Dimension::from_length(320f32),
140 height: taffy::style::Dimension::from_length(640f32),
141 },
142 ..Default::default()
143 },
144 &[node0, node1, node2],
145 )
146 .unwrap();
147 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
148 println!("\nComputed tree:");
149 taffy.print_tree(node);
150 println!();
151 let layout = taffy.layout(node).unwrap();
152 let Layout { size, location, .. } = layout;
153 assert_eq!(size.width, 320f32, "width of node {:?}. Expected {}. Actual {}", node, 320f32, size.width);
154 assert_eq!(size.height, 640f32, "height of node {:?}. Expected {}. Actual {}", node, 640f32, size.height);
155 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
156 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
157 let layout = taffy.layout(node0).unwrap();
158 let Layout { size, location, .. } = layout;
159 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
160 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
161 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
162 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
163 let layout = taffy.layout(node1).unwrap();
164 let Layout { size, location, .. } = layout;
165 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
166 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node1, 30f32, size.height);
167 assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node1, 100f32, location.x);
168 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
169 let layout = taffy.layout(node2).unwrap();
170 let Layout { size, location, .. } = layout;
171 assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node2, 120f32, size.width);
172 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
173 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
174 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node2, 50f32, location.y);
175}