tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1068HTML 999Markdown 12TOML 83188 Sutichaykuna

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/flex/flex_wrap_wrap_to_child_height.rs Rust · 179 siq'ikuna · 9.2 KB Ñawpa willay Pi imata llamkarqan ch'uya

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn flex_wrap_wrap_to_child_height__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node000 = taffy
8        .new_leaf(taffy::style::Style {
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::from_length(100f32),
11                height: taffy::style::Dimension::from_length(100f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node00 = taffy
17        .new_with_children(
18            taffy::style::Style {
19                flex_direction: taffy::style::FlexDirection::Column,
20                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(100f32), height: auto() },
21                ..Default::default()
22            },
23            &[node000],
24        )
25        .unwrap();
26    let node0 = taffy
27        .new_with_children(
28            taffy::style::Style {
29                flex_wrap: taffy::style::FlexWrap::Wrap,
30                align_items: Some(taffy::style::AlignItems::FlexStart),
31                ..Default::default()
32            },
33            &[node00],
34        )
35        .unwrap();
36    let node1 = taffy
37        .new_leaf(taffy::style::Style {
38            size: taffy::geometry::Size {
39                width: taffy::style::Dimension::from_length(100f32),
40                height: taffy::style::Dimension::from_length(100f32),
41            },
42            ..Default::default()
43        })
44        .unwrap();
45    let node = taffy
46        .new_with_children(
47            taffy::style::Style { flex_direction: taffy::style::FlexDirection::Column, ..Default::default() },
48            &[node0, node1],
49        )
50        .unwrap();
51    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
52    println!("\nComputed tree:");
53    taffy.print_tree(node);
54    println!();
55    let layout = taffy.layout(node).unwrap();
56    let Layout { size, location, .. } = layout;
57    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
58    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
59    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
60    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
61    let layout = taffy.layout(node0).unwrap();
62    let Layout { size, location, .. } = layout;
63    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
64    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
65    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
66    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
67    let layout = taffy.layout(node00).unwrap();
68    let Layout { size, location, .. } = layout;
69    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node00, 100f32, size.width);
70    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node00, 100f32, size.height);
71    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
72    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
73    let layout = taffy.layout(node000).unwrap();
74    let Layout { size, location, .. } = layout;
75    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node000, 100f32, size.width);
76    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node000, 100f32, size.height);
77    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000, 0f32, location.x);
78    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node000, 0f32, location.y);
79    let layout = taffy.layout(node1).unwrap();
80    let Layout { size, location, .. } = layout;
81    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
82    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1, 100f32, size.height);
83    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
84    assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node1, 100f32, location.y);
85}
86
87#[test]
88#[allow(non_snake_case)]
89fn flex_wrap_wrap_to_child_height__content_box() {
90    #[allow(unused_imports)]
91    use taffy::{prelude::*, Layout};
92    let mut taffy = crate::new_test_tree();
93    let node000 = taffy
94        .new_leaf(taffy::style::Style {
95            box_sizing: taffy::style::BoxSizing::ContentBox,
96            size: taffy::geometry::Size {
97                width: taffy::style::Dimension::from_length(100f32),
98                height: taffy::style::Dimension::from_length(100f32),
99            },
100            ..Default::default()
101        })
102        .unwrap();
103    let node00 = taffy
104        .new_with_children(
105            taffy::style::Style {
106                box_sizing: taffy::style::BoxSizing::ContentBox,
107                flex_direction: taffy::style::FlexDirection::Column,
108                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(100f32), height: auto() },
109                ..Default::default()
110            },
111            &[node000],
112        )
113        .unwrap();
114    let node0 = taffy
115        .new_with_children(
116            taffy::style::Style {
117                box_sizing: taffy::style::BoxSizing::ContentBox,
118                flex_wrap: taffy::style::FlexWrap::Wrap,
119                align_items: Some(taffy::style::AlignItems::FlexStart),
120                ..Default::default()
121            },
122            &[node00],
123        )
124        .unwrap();
125    let node1 = taffy
126        .new_leaf(taffy::style::Style {
127            box_sizing: taffy::style::BoxSizing::ContentBox,
128            size: taffy::geometry::Size {
129                width: taffy::style::Dimension::from_length(100f32),
130                height: taffy::style::Dimension::from_length(100f32),
131            },
132            ..Default::default()
133        })
134        .unwrap();
135    let node = taffy
136        .new_with_children(
137            taffy::style::Style {
138                box_sizing: taffy::style::BoxSizing::ContentBox,
139                flex_direction: taffy::style::FlexDirection::Column,
140                ..Default::default()
141            },
142            &[node0, node1],
143        )
144        .unwrap();
145    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
146    println!("\nComputed tree:");
147    taffy.print_tree(node);
148    println!();
149    let layout = taffy.layout(node).unwrap();
150    let Layout { size, location, .. } = layout;
151    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
152    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
153    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
154    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
155    let layout = taffy.layout(node0).unwrap();
156    let Layout { size, location, .. } = layout;
157    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
158    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
159    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
160    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
161    let layout = taffy.layout(node00).unwrap();
162    let Layout { size, location, .. } = layout;
163    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node00, 100f32, size.width);
164    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node00, 100f32, size.height);
165    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
166    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
167    let layout = taffy.layout(node000).unwrap();
168    let Layout { size, location, .. } = layout;
169    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node000, 100f32, size.width);
170    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node000, 100f32, size.height);
171    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000, 0f32, location.x);
172    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node000, 0f32, location.y);
173    let layout = taffy.layout(node1).unwrap();
174    let Layout { size, location, .. } = layout;
175    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
176    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1, 100f32, size.height);
177    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
178    assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node1, 100f32, location.y);
179}