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