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