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