tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Definiciones

⎇ 84ab99503e62e45b86f9871c67ecf50188b95468 tests/generated/grid/grid_taffy_issue_591.rs Rust · 284 líneas · 11.8 KB Historia Quién tocó qué crudo

Fix intrinsic sizing min size (#723) 84ab99503 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn grid_taffy_issue_591__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, tree::Layout, TaffyTree};
6    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
7    let node00 = taffy
8        .new_leaf(taffy::style::Style {
9            display: taffy::style::Display::Flex,
10            min_size: taffy::geometry::Size {
11                width: taffy::style::Dimension::Length(50f32),
12                height: taffy::style::Dimension::Length(50f32),
13            },
14            padding: taffy::geometry::Rect {
15                left: taffy::style::LengthPercentage::Length(10f32),
16                right: taffy::style::LengthPercentage::Length(10f32),
17                top: taffy::style::LengthPercentage::Length(10f32),
18                bottom: taffy::style::LengthPercentage::Length(10f32),
19            },
20            ..Default::default()
21        })
22        .unwrap();
23    let node0 = taffy
24        .new_with_children(
25            taffy::style::Style {
26                display: taffy::style::Display::Flex,
27                position: taffy::style::Position::Absolute,
28                align_items: Some(taffy::style::AlignItems::Center),
29                justify_content: Some(taffy::style::JustifyContent::Center),
30                max_size: taffy::geometry::Size {
31                    width: taffy::style::Dimension::Length(100f32),
32                    height: taffy::style::Dimension::Length(100f32),
33                },
34                padding: taffy::geometry::Rect {
35                    left: taffy::style::LengthPercentage::Length(10f32),
36                    right: taffy::style::LengthPercentage::Length(10f32),
37                    top: taffy::style::LengthPercentage::Length(10f32),
38                    bottom: taffy::style::LengthPercentage::Length(10f32),
39                },
40                inset: taffy::geometry::Rect {
41                    left: taffy::style::LengthPercentageAuto::Length(0f32),
42                    right: auto(),
43                    top: taffy::style::LengthPercentageAuto::Length(0f32),
44                    bottom: auto(),
45                },
46                ..Default::default()
47            },
48            &[node00],
49        )
50        .unwrap();
51    let node = taffy
52        .new_with_children(
53            taffy::style::Style {
54                display: taffy::style::Display::Flex,
55                size: taffy::geometry::Size {
56                    width: taffy::style::Dimension::Length(300f32),
57                    height: taffy::style::Dimension::Length(200f32),
58                },
59                ..Default::default()
60            },
61            &[node0],
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, 300f32, "width of node {:?}. Expected {}. Actual {}", node, 300f32, size.width);
71    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, 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        0f32,
78        "scroll_width of node {:?}. Expected {}. Actual {}",
79        node,
80        0f32,
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, 70f32, "width of node {:?}. Expected {}. Actual {}", node0, 70f32, size.width);
95    assert_eq!(size.height, 70f32, "height of node {:?}. Expected {}. Actual {}", node0, 70f32, size.height);
96    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
97    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, 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(node00).unwrap();
118    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
119    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node00, 50f32, size.height);
120    assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node00, 10f32, location.x);
121    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node00, 10f32, location.y);
122    #[cfg(feature = "content_size")]
123    assert_eq!(
124        layout.scroll_width(),
125        0f32,
126        "scroll_width of node {:?}. Expected {}. Actual {}",
127        node00,
128        0f32,
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        node00,
137        0f32,
138        layout.scroll_height()
139    );
140}
141
142#[test]
143#[allow(non_snake_case)]
144fn grid_taffy_issue_591__content_box() {
145    #[allow(unused_imports)]
146    use taffy::{prelude::*, tree::Layout, TaffyTree};
147    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
148    let node00 = taffy
149        .new_leaf(taffy::style::Style {
150            display: taffy::style::Display::Flex,
151            box_sizing: taffy::style::BoxSizing::ContentBox,
152            min_size: taffy::geometry::Size {
153                width: taffy::style::Dimension::Length(50f32),
154                height: taffy::style::Dimension::Length(50f32),
155            },
156            padding: taffy::geometry::Rect {
157                left: taffy::style::LengthPercentage::Length(10f32),
158                right: taffy::style::LengthPercentage::Length(10f32),
159                top: taffy::style::LengthPercentage::Length(10f32),
160                bottom: taffy::style::LengthPercentage::Length(10f32),
161            },
162            ..Default::default()
163        })
164        .unwrap();
165    let node0 = taffy
166        .new_with_children(
167            taffy::style::Style {
168                display: taffy::style::Display::Flex,
169                box_sizing: taffy::style::BoxSizing::ContentBox,
170                position: taffy::style::Position::Absolute,
171                align_items: Some(taffy::style::AlignItems::Center),
172                justify_content: Some(taffy::style::JustifyContent::Center),
173                max_size: taffy::geometry::Size {
174                    width: taffy::style::Dimension::Length(100f32),
175                    height: taffy::style::Dimension::Length(100f32),
176                },
177                padding: taffy::geometry::Rect {
178                    left: taffy::style::LengthPercentage::Length(10f32),
179                    right: taffy::style::LengthPercentage::Length(10f32),
180                    top: taffy::style::LengthPercentage::Length(10f32),
181                    bottom: taffy::style::LengthPercentage::Length(10f32),
182                },
183                inset: taffy::geometry::Rect {
184                    left: taffy::style::LengthPercentageAuto::Length(0f32),
185                    right: auto(),
186                    top: taffy::style::LengthPercentageAuto::Length(0f32),
187                    bottom: auto(),
188                },
189                ..Default::default()
190            },
191            &[node00],
192        )
193        .unwrap();
194    let node = taffy
195        .new_with_children(
196            taffy::style::Style {
197                display: taffy::style::Display::Flex,
198                box_sizing: taffy::style::BoxSizing::ContentBox,
199                size: taffy::geometry::Size {
200                    width: taffy::style::Dimension::Length(300f32),
201                    height: taffy::style::Dimension::Length(200f32),
202                },
203                ..Default::default()
204            },
205            &[node0],
206        )
207        .unwrap();
208    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
209    println!("\nComputed tree:");
210    taffy.print_tree(node);
211    println!();
212    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
213    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
214    assert_eq!(size.width, 300f32, "width of node {:?}. Expected {}. Actual {}", node, 300f32, size.width);
215    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
216    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
217    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
218    #[cfg(feature = "content_size")]
219    assert_eq!(
220        layout.scroll_width(),
221        0f32,
222        "scroll_width of node {:?}. Expected {}. Actual {}",
223        node,
224        0f32,
225        layout.scroll_width()
226    );
227    #[cfg(feature = "content_size")]
228    assert_eq!(
229        layout.scroll_height(),
230        0f32,
231        "scroll_height of node {:?}. Expected {}. Actual {}",
232        node,
233        0f32,
234        layout.scroll_height()
235    );
236    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
237    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
238    assert_eq!(size.width, 90f32, "width of node {:?}. Expected {}. Actual {}", node0, 90f32, size.width);
239    assert_eq!(size.height, 90f32, "height of node {:?}. Expected {}. Actual {}", node0, 90f32, size.height);
240    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
241    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
242    #[cfg(feature = "content_size")]
243    assert_eq!(
244        layout.scroll_width(),
245        0f32,
246        "scroll_width of node {:?}. Expected {}. Actual {}",
247        node0,
248        0f32,
249        layout.scroll_width()
250    );
251    #[cfg(feature = "content_size")]
252    assert_eq!(
253        layout.scroll_height(),
254        0f32,
255        "scroll_height of node {:?}. Expected {}. Actual {}",
256        node0,
257        0f32,
258        layout.scroll_height()
259    );
260    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
261    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
262    assert_eq!(size.width, 70f32, "width of node {:?}. Expected {}. Actual {}", node00, 70f32, size.width);
263    assert_eq!(size.height, 70f32, "height of node {:?}. Expected {}. Actual {}", node00, 70f32, size.height);
264    assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node00, 10f32, location.x);
265    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node00, 10f32, location.y);
266    #[cfg(feature = "content_size")]
267    assert_eq!(
268        layout.scroll_width(),
269        0f32,
270        "scroll_width of node {:?}. Expected {}. Actual {}",
271        node00,
272        0f32,
273        layout.scroll_width()
274    );
275    #[cfg(feature = "content_size")]
276    assert_eq!(
277        layout.scroll_height(),
278        0f32,
279        "scroll_height of node {:?}. Expected {}. Actual {}",
280        node00,
281        0f32,
282        layout.scroll_height()
283    );
284}