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