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