tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 9TOML 3CSS 1345 Definiciones

⎇ 40dd6120fc73aa866f30e52a51d1abaf39adce6f tests/generated/flex/wrapped_column_max_height_flex.rs Rust · 189 líneas · 9.6 KB Historia Quién tocó qué crudo

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

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