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