Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn flex_grow_shrink_at_most__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node00 =
8 taffy.new_leaf(taffy::style::Style { flex_grow: 1f32, flex_shrink: 1f32, ..Default::default() }).unwrap();
9 let node0 = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node00]).unwrap();
10 let node = taffy
11 .new_with_children(
12 taffy::style::Style {
13 size: taffy::geometry::Size {
14 width: taffy::style::Dimension::from_length(100f32),
15 height: taffy::style::Dimension::from_length(100f32),
16 },
17 ..Default::default()
18 },
19 &[node0],
20 )
21 .unwrap();
22 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
23 println!("\nComputed tree:");
24 taffy.print_tree(node);
25 println!();
26 let layout = taffy.layout(node).unwrap();
27 let Layout { size, location, .. } = layout;
28 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
29 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
30 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
31 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
32 let layout = taffy.layout(node0).unwrap();
33 let Layout { size, location, .. } = layout;
34 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node0, 0f32, size.width);
35 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
36 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
37 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
38 let layout = taffy.layout(node00).unwrap();
39 let Layout { size, location, .. } = layout;
40 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node00, 0f32, size.width);
41 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node00, 100f32, size.height);
42 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
43 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
44}
45
46#[test]
47#[allow(non_snake_case)]
48fn flex_grow_shrink_at_most__content_box() {
49 #[allow(unused_imports)]
50 use taffy::{prelude::*, Layout};
51 let mut taffy = crate::new_test_tree();
52 let node00 = taffy
53 .new_leaf(taffy::style::Style {
54 box_sizing: taffy::style::BoxSizing::ContentBox,
55 flex_grow: 1f32,
56 flex_shrink: 1f32,
57 ..Default::default()
58 })
59 .unwrap();
60 let node0 = taffy
61 .new_with_children(
62 taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
63 &[node00],
64 )
65 .unwrap();
66 let node = taffy
67 .new_with_children(
68 taffy::style::Style {
69 box_sizing: taffy::style::BoxSizing::ContentBox,
70 size: taffy::geometry::Size {
71 width: taffy::style::Dimension::from_length(100f32),
72 height: taffy::style::Dimension::from_length(100f32),
73 },
74 ..Default::default()
75 },
76 &[node0],
77 )
78 .unwrap();
79 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
80 println!("\nComputed tree:");
81 taffy.print_tree(node);
82 println!();
83 let layout = taffy.layout(node).unwrap();
84 let Layout { size, location, .. } = layout;
85 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
86 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
87 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
88 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
89 let layout = taffy.layout(node0).unwrap();
90 let Layout { size, location, .. } = layout;
91 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node0, 0f32, size.width);
92 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
93 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
94 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
95 let layout = taffy.layout(node00).unwrap();
96 let Layout { size, location, .. } = layout;
97 assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node00, 0f32, size.width);
98 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node00, 100f32, size.height);
99 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
100 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
101}