⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2
tests/generated/flex/percent_within_flex_grow.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 percent_within_flex_grow__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: taffy::style::Dimension::from_length(100f32), height: auto() },
10 ..Default::default()
11 })
12 .unwrap();
13 let node10 = taffy
14 .new_leaf(taffy::style::Style {
15 size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(1f32), height: auto() },
16 ..Default::default()
17 })
18 .unwrap();
19 let node1 = taffy
20 .new_with_children(
21 taffy::style::Style {
22 flex_direction: taffy::style::FlexDirection::Column,
23 flex_grow: 1f32,
24 ..Default::default()
25 },
26 &[node10],
27 )
28 .unwrap();
29 let node2 = taffy
30 .new_leaf(taffy::style::Style {
31 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(100f32), height: auto() },
32 ..Default::default()
33 })
34 .unwrap();
35 let node = taffy
36 .new_with_children(
37 taffy::style::Style {
38 size: taffy::geometry::Size {
39 width: taffy::style::Dimension::from_length(350f32),
40 height: taffy::style::Dimension::from_length(100f32),
41 },
42 ..Default::default()
43 },
44 &[node0, node1, node2],
45 )
46 .unwrap();
47 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
48 println!("\nComputed tree:");
49 taffy.print_tree(node);
50 println!();
51 let layout = taffy.layout(node).unwrap();
52 let Layout { size, location, .. } = layout;
53 assert_eq!(size.width, 350f32, "width of node {:?}. Expected {}. Actual {}", node, 350f32, size.width);
54 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
55 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
56 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
57 let layout = taffy.layout(node0).unwrap();
58 let Layout { size, location, .. } = layout;
59 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
60 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
61 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
62 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
63 let layout = taffy.layout(node1).unwrap();
64 let Layout { size, location, .. } = layout;
65 assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node1, 150f32, size.width);
66 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1, 100f32, size.height);
67 assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node1, 100f32, location.x);
68 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
69 let layout = taffy.layout(node10).unwrap();
70 let Layout { size, location, .. } = layout;
71 assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node10, 150f32, size.width);
72 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node10, 0f32, size.height);
73 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
74 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
75 let layout = taffy.layout(node2).unwrap();
76 let Layout { size, location, .. } = layout;
77 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width);
78 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node2, 100f32, size.height);
79 assert_eq!(location.x, 250f32, "x of node {:?}. Expected {}. Actual {}", node2, 250f32, location.x);
80 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
81}
82
83#[test]
84#[allow(non_snake_case)]
85fn percent_within_flex_grow__content_box() {
86 #[allow(unused_imports)]
87 use taffy::{prelude::*, Layout};
88 let mut taffy = crate::new_test_tree();
89 let node0 = taffy
90 .new_leaf(taffy::style::Style {
91 box_sizing: taffy::style::BoxSizing::ContentBox,
92 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(100f32), height: auto() },
93 ..Default::default()
94 })
95 .unwrap();
96 let node10 = taffy
97 .new_leaf(taffy::style::Style {
98 box_sizing: taffy::style::BoxSizing::ContentBox,
99 size: taffy::geometry::Size { width: taffy::style::Dimension::from_percent(1f32), height: auto() },
100 ..Default::default()
101 })
102 .unwrap();
103 let node1 = taffy
104 .new_with_children(
105 taffy::style::Style {
106 box_sizing: taffy::style::BoxSizing::ContentBox,
107 flex_direction: taffy::style::FlexDirection::Column,
108 flex_grow: 1f32,
109 ..Default::default()
110 },
111 &[node10],
112 )
113 .unwrap();
114 let node2 = taffy
115 .new_leaf(taffy::style::Style {
116 box_sizing: taffy::style::BoxSizing::ContentBox,
117 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(100f32), height: auto() },
118 ..Default::default()
119 })
120 .unwrap();
121 let node = taffy
122 .new_with_children(
123 taffy::style::Style {
124 box_sizing: taffy::style::BoxSizing::ContentBox,
125 size: taffy::geometry::Size {
126 width: taffy::style::Dimension::from_length(350f32),
127 height: taffy::style::Dimension::from_length(100f32),
128 },
129 ..Default::default()
130 },
131 &[node0, node1, node2],
132 )
133 .unwrap();
134 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
135 println!("\nComputed tree:");
136 taffy.print_tree(node);
137 println!();
138 let layout = taffy.layout(node).unwrap();
139 let Layout { size, location, .. } = layout;
140 assert_eq!(size.width, 350f32, "width of node {:?}. Expected {}. Actual {}", node, 350f32, size.width);
141 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
142 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
143 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
144 let layout = taffy.layout(node0).unwrap();
145 let Layout { size, location, .. } = layout;
146 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
147 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
148 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
149 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
150 let layout = taffy.layout(node1).unwrap();
151 let Layout { size, location, .. } = layout;
152 assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node1, 150f32, size.width);
153 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1, 100f32, size.height);
154 assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node1, 100f32, location.x);
155 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
156 let layout = taffy.layout(node10).unwrap();
157 let Layout { size, location, .. } = layout;
158 assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node10, 150f32, size.width);
159 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node10, 0f32, size.height);
160 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
161 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
162 let layout = taffy.layout(node2).unwrap();
163 let Layout { size, location, .. } = layout;
164 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width);
165 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node2, 100f32, size.height);
166 assert_eq!(location.x, 250f32, "x of node {:?}. Expected {}. Actual {}", node2, 250f32, location.x);
167 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
168}