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