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