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