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