⎇ 8dfff821180dea3cab0443c1ef712242369d2e29
tests/generated/flex/margin_auto_mutiple_children_row.rs
Historia
Quién tocó qué
crudo
Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn margin_auto_mutiple_children_row() {
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 size: taffy::geometry::Size {
9 width: taffy::style::Dimension::Length(50f32),
10 height: taffy::style::Dimension::Length(50f32),
11 },
12 margin: taffy::geometry::Rect {
13 left: zero(),
14 right: taffy::style::LengthPercentageAuto::Auto,
15 top: zero(),
16 bottom: zero(),
17 },
18 ..Default::default()
19 })
20 .unwrap();
21 let node1 = taffy
22 .new_leaf(taffy::style::Style {
23 size: taffy::geometry::Size {
24 width: taffy::style::Dimension::Length(50f32),
25 height: taffy::style::Dimension::Length(50f32),
26 },
27 margin: taffy::geometry::Rect {
28 left: zero(),
29 right: taffy::style::LengthPercentageAuto::Auto,
30 top: zero(),
31 bottom: zero(),
32 },
33 ..Default::default()
34 })
35 .unwrap();
36 let node2 = taffy
37 .new_leaf(taffy::style::Style {
38 size: taffy::geometry::Size {
39 width: taffy::style::Dimension::Length(50f32),
40 height: taffy::style::Dimension::Length(50f32),
41 },
42 ..Default::default()
43 })
44 .unwrap();
45 let node = taffy
46 .new_with_children(
47 taffy::style::Style {
48 align_items: Some(taffy::style::AlignItems::Center),
49 size: taffy::geometry::Size {
50 width: taffy::style::Dimension::Length(200f32),
51 height: taffy::style::Dimension::Length(200f32),
52 },
53 ..Default::default()
54 },
55 &[node0, node1, node2],
56 )
57 .unwrap();
58 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
59 println!("\nComputed tree:");
60 taffy.print_tree(node);
61 println!();
62 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
63 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
64 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
65 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
66 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
67 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
68 #[cfg(feature = "content_size")]
69 assert_eq!(
70 layout.scroll_width(),
71 0f32,
72 "scroll_width of node {:?}. Expected {}. Actual {}",
73 node,
74 0f32,
75 layout.scroll_width()
76 );
77 #[cfg(feature = "content_size")]
78 assert_eq!(
79 layout.scroll_height(),
80 0f32,
81 "scroll_height of node {:?}. Expected {}. Actual {}",
82 node,
83 0f32,
84 layout.scroll_height()
85 );
86 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
87 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
88 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
89 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
90 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
91 assert_eq!(location.y, 75f32, "y of node {:?}. Expected {}. Actual {}", node0, 75f32, location.y);
92 #[cfg(feature = "content_size")]
93 assert_eq!(
94 layout.scroll_width(),
95 0f32,
96 "scroll_width of node {:?}. Expected {}. Actual {}",
97 node0,
98 0f32,
99 layout.scroll_width()
100 );
101 #[cfg(feature = "content_size")]
102 assert_eq!(
103 layout.scroll_height(),
104 0f32,
105 "scroll_height of node {:?}. Expected {}. Actual {}",
106 node0,
107 0f32,
108 layout.scroll_height()
109 );
110 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
111 let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
112 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
113 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
114 assert_eq!(location.x, 75f32, "x of node {:?}. Expected {}. Actual {}", node1, 75f32, location.x);
115 assert_eq!(location.y, 75f32, "y of node {:?}. Expected {}. Actual {}", node1, 75f32, location.y);
116 #[cfg(feature = "content_size")]
117 assert_eq!(
118 layout.scroll_width(),
119 0f32,
120 "scroll_width of node {:?}. Expected {}. Actual {}",
121 node1,
122 0f32,
123 layout.scroll_width()
124 );
125 #[cfg(feature = "content_size")]
126 assert_eq!(
127 layout.scroll_height(),
128 0f32,
129 "scroll_height of node {:?}. Expected {}. Actual {}",
130 node1,
131 0f32,
132 layout.scroll_height()
133 );
134 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
135 let layout @ Layout { size, location, .. } = taffy.layout(node2).unwrap();
136 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
137 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2, 50f32, size.height);
138 assert_eq!(location.x, 150f32, "x of node {:?}. Expected {}. Actual {}", node2, 150f32, location.x);
139 assert_eq!(location.y, 75f32, "y of node {:?}. Expected {}. Actual {}", node2, 75f32, location.y);
140 #[cfg(feature = "content_size")]
141 assert_eq!(
142 layout.scroll_width(),
143 0f32,
144 "scroll_width of node {:?}. Expected {}. Actual {}",
145 node2,
146 0f32,
147 layout.scroll_width()
148 );
149 #[cfg(feature = "content_size")]
150 assert_eq!(
151 layout.scroll_height(),
152 0f32,
153 "scroll_height of node {:?}. Expected {}. Actual {}",
154 node2,
155 0f32,
156 layout.scroll_height()
157 );
158}