⎇ direction-floats
tests/generated/flex/gap_row_gap_determines_parent_height.rs
History
Who touched what
raw
Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn gap_row_gap_determines_parent_height__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 ..Default::default()
11 })
12 .unwrap();
13 let node1 = taffy
14 .new_leaf(taffy::style::Style {
15 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(20f32) },
16 ..Default::default()
17 })
18 .unwrap();
19 let node2 = taffy
20 .new_leaf(taffy::style::Style {
21 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(30f32) },
22 ..Default::default()
23 })
24 .unwrap();
25 let node = taffy
26 .new_with_children(
27 taffy::style::Style {
28 flex_direction: taffy::style::FlexDirection::Column,
29 align_items: Some(taffy::style::AlignItems::Stretch),
30 gap: taffy::geometry::Size { width: zero(), height: length(10f32) },
31 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(100f32), height: auto() },
32 ..Default::default()
33 },
34 &[node0, node1, node2],
35 )
36 .unwrap();
37 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
38 println!("\nComputed tree:");
39 taffy.print_tree(node);
40 println!();
41 let layout = taffy.layout(node).unwrap();
42 let Layout { size, location, .. } = layout;
43 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
44 assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node, 80f32, size.height);
45 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
46 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
47 let layout = taffy.layout(node0).unwrap();
48 let Layout { size, location, .. } = layout;
49 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
50 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
51 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
52 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
53 let layout = taffy.layout(node1).unwrap();
54 let Layout { size, location, .. } = layout;
55 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
56 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
57 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
58 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node1, 20f32, location.y);
59 let layout = taffy.layout(node2).unwrap();
60 let Layout { size, location, .. } = layout;
61 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width);
62 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node2, 30f32, size.height);
63 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
64 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node2, 50f32, location.y);
65}
66
67#[test]
68#[allow(non_snake_case)]
69fn gap_row_gap_determines_parent_height__content_box() {
70 #[allow(unused_imports)]
71 use taffy::{prelude::*, Layout};
72 let mut taffy = crate::new_test_tree();
73 let node0 = taffy
74 .new_leaf(taffy::style::Style {
75 box_sizing: taffy::style::BoxSizing::ContentBox,
76 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
77 ..Default::default()
78 })
79 .unwrap();
80 let node1 = taffy
81 .new_leaf(taffy::style::Style {
82 box_sizing: taffy::style::BoxSizing::ContentBox,
83 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(20f32) },
84 ..Default::default()
85 })
86 .unwrap();
87 let node2 = taffy
88 .new_leaf(taffy::style::Style {
89 box_sizing: taffy::style::BoxSizing::ContentBox,
90 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(30f32) },
91 ..Default::default()
92 })
93 .unwrap();
94 let node = taffy
95 .new_with_children(
96 taffy::style::Style {
97 box_sizing: taffy::style::BoxSizing::ContentBox,
98 flex_direction: taffy::style::FlexDirection::Column,
99 align_items: Some(taffy::style::AlignItems::Stretch),
100 gap: taffy::geometry::Size { width: zero(), height: length(10f32) },
101 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(100f32), height: auto() },
102 ..Default::default()
103 },
104 &[node0, node1, node2],
105 )
106 .unwrap();
107 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
108 println!("\nComputed tree:");
109 taffy.print_tree(node);
110 println!();
111 let layout = taffy.layout(node).unwrap();
112 let Layout { size, location, .. } = layout;
113 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
114 assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node, 80f32, size.height);
115 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
116 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
117 let layout = taffy.layout(node0).unwrap();
118 let Layout { size, location, .. } = layout;
119 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
120 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
121 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
122 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
123 let layout = taffy.layout(node1).unwrap();
124 let Layout { size, location, .. } = layout;
125 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
126 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
127 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
128 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node1, 20f32, location.y);
129 let layout = taffy.layout(node2).unwrap();
130 let Layout { size, location, .. } = layout;
131 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width);
132 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node2, 30f32, size.height);
133 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
134 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node2, 50f32, location.y);
135}