⎇ 0.5.x
tests/generated/flex/rounding_inner_node_controversy_horizontal.rs
History
Who touched what
raw
Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn rounding_inner_node_controversy_horizontal() {
3 #[allow(unused_imports)]
4 use taffy::{prelude::*, tree::Layout, TaffyTree};
5 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6 let node0 = taffy
7 .new_leaf(taffy::style::Style {
8 flex_grow: 1f32,
9 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
10 ..Default::default()
11 })
12 .unwrap();
13 let node10 = taffy
14 .new_leaf(taffy::style::Style {
15 flex_grow: 1f32,
16 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
17 ..Default::default()
18 })
19 .unwrap();
20 let node1 = taffy
21 .new_with_children(
22 taffy::style::Style {
23 flex_direction: taffy::style::FlexDirection::Column,
24 flex_grow: 1f32,
25 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
26 ..Default::default()
27 },
28 &[node10],
29 )
30 .unwrap();
31 let node2 = taffy
32 .new_leaf(taffy::style::Style {
33 flex_grow: 1f32,
34 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
35 ..Default::default()
36 })
37 .unwrap();
38 let node = taffy
39 .new_with_children(
40 taffy::style::Style {
41 size: taffy::geometry::Size { width: taffy::style::Dimension::Length(320f32), height: auto() },
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 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
52 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
53 assert_eq!(size.width, 320f32, "width of node {:?}. Expected {}. Actual {}", node, 320f32, size.width);
54 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node, 10f32, 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 #[cfg(feature = "content_size")]
58 assert_eq!(
59 layout.scroll_width(),
60 0f32,
61 "scroll_width of node {:?}. Expected {}. Actual {}",
62 node,
63 0f32,
64 layout.scroll_width()
65 );
66 #[cfg(feature = "content_size")]
67 assert_eq!(
68 layout.scroll_height(),
69 0f32,
70 "scroll_height of node {:?}. Expected {}. Actual {}",
71 node,
72 0f32,
73 layout.scroll_height()
74 );
75 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
76 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
77 assert_eq!(size.width, 107f32, "width of node {:?}. Expected {}. Actual {}", node0, 107f32, size.width);
78 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
79 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
80 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
81 #[cfg(feature = "content_size")]
82 assert_eq!(
83 layout.scroll_width(),
84 0f32,
85 "scroll_width of node {:?}. Expected {}. Actual {}",
86 node0,
87 0f32,
88 layout.scroll_width()
89 );
90 #[cfg(feature = "content_size")]
91 assert_eq!(
92 layout.scroll_height(),
93 0f32,
94 "scroll_height of node {:?}. Expected {}. Actual {}",
95 node0,
96 0f32,
97 layout.scroll_height()
98 );
99 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
100 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
101 assert_eq!(size.width, 106f32, "width of node {:?}. Expected {}. Actual {}", node1, 106f32, size.width);
102 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
103 assert_eq!(location.x, 107f32, "x of node {:?}. Expected {}. Actual {}", node1, 107f32, location.x);
104 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
105 #[cfg(feature = "content_size")]
106 assert_eq!(
107 layout.scroll_width(),
108 0f32,
109 "scroll_width of node {:?}. Expected {}. Actual {}",
110 node1,
111 0f32,
112 layout.scroll_width()
113 );
114 #[cfg(feature = "content_size")]
115 assert_eq!(
116 layout.scroll_height(),
117 0f32,
118 "scroll_height of node {:?}. Expected {}. Actual {}",
119 node1,
120 0f32,
121 layout.scroll_height()
122 );
123 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
124 let layout @ Layout { size, location, .. } = taffy.layout(node10).unwrap();
125 assert_eq!(size.width, 106f32, "width of node {:?}. Expected {}. Actual {}", node10, 106f32, size.width);
126 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
127 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
128 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
129 #[cfg(feature = "content_size")]
130 assert_eq!(
131 layout.scroll_width(),
132 0f32,
133 "scroll_width of node {:?}. Expected {}. Actual {}",
134 node10,
135 0f32,
136 layout.scroll_width()
137 );
138 #[cfg(feature = "content_size")]
139 assert_eq!(
140 layout.scroll_height(),
141 0f32,
142 "scroll_height of node {:?}. Expected {}. Actual {}",
143 node10,
144 0f32,
145 layout.scroll_height()
146 );
147 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
148 let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
149 assert_eq!(size.width, 107f32, "width of node {:?}. Expected {}. Actual {}", node2, 107f32, size.width);
150 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
151 assert_eq!(location.x, 213f32, "x of node {:?}. Expected {}. Actual {}", node2, 213f32, location.x);
152 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
153 #[cfg(feature = "content_size")]
154 assert_eq!(
155 layout.scroll_width(),
156 0f32,
157 "scroll_width of node {:?}. Expected {}. Actual {}",
158 node2,
159 0f32,
160 layout.scroll_width()
161 );
162 #[cfg(feature = "content_size")]
163 assert_eq!(
164 layout.scroll_height(),
165 0f32,
166 "scroll_height of node {:?}. Expected {}. Actual {}",
167 node2,
168 0f32,
169 layout.scroll_height()
170 );
171}