Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn size_defined_by_child__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 {
10 width: taffy::style::Dimension::from_length(100f32),
11 height: taffy::style::Dimension::from_length(100f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0]).unwrap();
17 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
18 println!("\nComputed tree:");
19 taffy.print_tree(node);
20 println!();
21 let layout = taffy.layout(node).unwrap();
22 let Layout { size, location, .. } = layout;
23 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
24 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
25 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
26 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
27 let layout = taffy.layout(node0).unwrap();
28 let Layout { size, location, .. } = layout;
29 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
30 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
31 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
32 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
33}
34
35#[test]
36#[allow(non_snake_case)]
37fn size_defined_by_child__content_box() {
38 #[allow(unused_imports)]
39 use taffy::{prelude::*, Layout};
40 let mut taffy = crate::new_test_tree();
41 let node0 = taffy
42 .new_leaf(taffy::style::Style {
43 box_sizing: taffy::style::BoxSizing::ContentBox,
44 size: taffy::geometry::Size {
45 width: taffy::style::Dimension::from_length(100f32),
46 height: taffy::style::Dimension::from_length(100f32),
47 },
48 ..Default::default()
49 })
50 .unwrap();
51 let node = taffy
52 .new_with_children(
53 taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
54 &[node0],
55 )
56 .unwrap();
57 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
58 println!("\nComputed tree:");
59 taffy.print_tree(node);
60 println!();
61 let layout = taffy.layout(node).unwrap();
62 let Layout { size, location, .. } = layout;
63 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
64 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
65 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
66 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
67 let layout = taffy.layout(node0).unwrap();
68 let Layout { size, location, .. } = layout;
69 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
70 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
71 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
72 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
73}