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