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