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