⎇ float-layout
tests/generated/block/block_intrinsic_width.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn block_intrinsic_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 {
10 width: taffy::style::Dimension::from_length(50f32),
11 height: taffy::style::Dimension::from_length(10f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node1 = taffy
17 .new_leaf(taffy::style::Style {
18 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
19 ..Default::default()
20 })
21 .unwrap();
22 let node = taffy
23 .new_with_children(
24 taffy::style::Style { display: taffy::style::Display::Block, ..Default::default() },
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, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
35 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, 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, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
41 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, 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, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
47 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
48 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
49 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node1, 10f32, location.y);
50}
51
52#[test]
53#[allow(non_snake_case)]
54fn block_intrinsic_width__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 {
60 box_sizing: taffy::style::BoxSizing::ContentBox,
61 size: taffy::geometry::Size {
62 width: taffy::style::Dimension::from_length(50f32),
63 height: taffy::style::Dimension::from_length(10f32),
64 },
65 ..Default::default()
66 })
67 .unwrap();
68 let node1 = taffy
69 .new_leaf(taffy::style::Style {
70 box_sizing: taffy::style::BoxSizing::ContentBox,
71 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
72 ..Default::default()
73 })
74 .unwrap();
75 let node = taffy
76 .new_with_children(
77 taffy::style::Style {
78 display: taffy::style::Display::Block,
79 box_sizing: taffy::style::BoxSizing::ContentBox,
80 ..Default::default()
81 },
82 &[node0, node1],
83 )
84 .unwrap();
85 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
86 println!("\nComputed tree:");
87 taffy.print_tree(node);
88 println!();
89 let layout = taffy.layout(node).unwrap();
90 let Layout { size, location, .. } = layout;
91 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
92 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
93 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
94 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
95 let layout = taffy.layout(node0).unwrap();
96 let Layout { size, location, .. } = layout;
97 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
98 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
99 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
100 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
101 let layout = taffy.layout(node1).unwrap();
102 let Layout { size, location, .. } = layout;
103 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
104 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
105 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
106 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node1, 10f32, location.y);
107}