tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1111HTML 1039Markdown 12TOML 94541 Sutichaykuna

⎇ 3bc35ec3b541eea8ea62344722f155ce9b22e227 tests/generated/flex/undefined_width_with_min_max_row.rs Rust · 226 siq'ikuna · 9.0 KB Ñawpa willay Pi imata llamkarqan ch'uya

Implement `box-sizing: content-box` (#675) a4976764b · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn undefined_width_with_min_max_row__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            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::Length(30f32),
11                height: taffy::style::Dimension::Length(20f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node0 = taffy
17        .new_with_children(
18            taffy::style::Style {
19                min_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(60f32), height: auto() },
20                max_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(300f32), height: auto() },
21                ..Default::default()
22            },
23            &[node00],
24        )
25        .unwrap();
26    let node = taffy
27        .new_with_children(
28            taffy::style::Style {
29                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(50f32) },
30                ..Default::default()
31            },
32            &[node0],
33        )
34        .unwrap();
35    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
36    println!("\nComputed tree:");
37    taffy.print_tree(node);
38    println!();
39    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
40    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
41    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node, 60f32, size.width);
42    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
43    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
44    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
45    #[cfg(feature = "content_size")]
46    assert_eq!(
47        layout.scroll_width(),
48        0f32,
49        "scroll_width of node {:?}. Expected {}. Actual {}",
50        node,
51        0f32,
52        layout.scroll_width()
53    );
54    #[cfg(feature = "content_size")]
55    assert_eq!(
56        layout.scroll_height(),
57        0f32,
58        "scroll_height of node {:?}. Expected {}. Actual {}",
59        node,
60        0f32,
61        layout.scroll_height()
62    );
63    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
64    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
65    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0, 60f32, size.width);
66    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
67    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
68    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
69    #[cfg(feature = "content_size")]
70    assert_eq!(
71        layout.scroll_width(),
72        0f32,
73        "scroll_width of node {:?}. Expected {}. Actual {}",
74        node0,
75        0f32,
76        layout.scroll_width()
77    );
78    #[cfg(feature = "content_size")]
79    assert_eq!(
80        layout.scroll_height(),
81        0f32,
82        "scroll_height of node {:?}. Expected {}. Actual {}",
83        node0,
84        0f32,
85        layout.scroll_height()
86    );
87    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
88    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
89    assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node00, 30f32, size.width);
90    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
91    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
92    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
93    #[cfg(feature = "content_size")]
94    assert_eq!(
95        layout.scroll_width(),
96        0f32,
97        "scroll_width of node {:?}. Expected {}. Actual {}",
98        node00,
99        0f32,
100        layout.scroll_width()
101    );
102    #[cfg(feature = "content_size")]
103    assert_eq!(
104        layout.scroll_height(),
105        0f32,
106        "scroll_height of node {:?}. Expected {}. Actual {}",
107        node00,
108        0f32,
109        layout.scroll_height()
110    );
111}
112
113#[test]
114#[allow(non_snake_case)]
115fn undefined_width_with_min_max_row__content_box() {
116    #[allow(unused_imports)]
117    use taffy::{prelude::*, tree::Layout, TaffyTree};
118    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
119    let node00 = taffy
120        .new_leaf(taffy::style::Style {
121            box_sizing: taffy::style::BoxSizing::ContentBox,
122            size: taffy::geometry::Size {
123                width: taffy::style::Dimension::Length(30f32),
124                height: taffy::style::Dimension::Length(20f32),
125            },
126            ..Default::default()
127        })
128        .unwrap();
129    let node0 = taffy
130        .new_with_children(
131            taffy::style::Style {
132                box_sizing: taffy::style::BoxSizing::ContentBox,
133                min_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(60f32), height: auto() },
134                max_size: taffy::geometry::Size { width: taffy::style::Dimension::Length(300f32), height: auto() },
135                ..Default::default()
136            },
137            &[node00],
138        )
139        .unwrap();
140    let node = taffy
141        .new_with_children(
142            taffy::style::Style {
143                box_sizing: taffy::style::BoxSizing::ContentBox,
144                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(50f32) },
145                ..Default::default()
146            },
147            &[node0],
148        )
149        .unwrap();
150    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
151    println!("\nComputed tree:");
152    taffy.print_tree(node);
153    println!();
154    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
155    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
156    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node, 60f32, size.width);
157    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
158    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
159    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
160    #[cfg(feature = "content_size")]
161    assert_eq!(
162        layout.scroll_width(),
163        0f32,
164        "scroll_width of node {:?}. Expected {}. Actual {}",
165        node,
166        0f32,
167        layout.scroll_width()
168    );
169    #[cfg(feature = "content_size")]
170    assert_eq!(
171        layout.scroll_height(),
172        0f32,
173        "scroll_height of node {:?}. Expected {}. Actual {}",
174        node,
175        0f32,
176        layout.scroll_height()
177    );
178    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
179    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
180    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0, 60f32, size.width);
181    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
182    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
183    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
184    #[cfg(feature = "content_size")]
185    assert_eq!(
186        layout.scroll_width(),
187        0f32,
188        "scroll_width of node {:?}. Expected {}. Actual {}",
189        node0,
190        0f32,
191        layout.scroll_width()
192    );
193    #[cfg(feature = "content_size")]
194    assert_eq!(
195        layout.scroll_height(),
196        0f32,
197        "scroll_height of node {:?}. Expected {}. Actual {}",
198        node0,
199        0f32,
200        layout.scroll_height()
201    );
202    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
203    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
204    assert_eq!(size.width, 30f32, "width of node {:?}. Expected {}. Actual {}", node00, 30f32, size.width);
205    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
206    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
207    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
208    #[cfg(feature = "content_size")]
209    assert_eq!(
210        layout.scroll_width(),
211        0f32,
212        "scroll_width of node {:?}. Expected {}. Actual {}",
213        node00,
214        0f32,
215        layout.scroll_width()
216    );
217    #[cfg(feature = "content_size")]
218    assert_eq!(
219        layout.scroll_height(),
220        0f32,
221        "scroll_height of node {:?}. Expected {}. Actual {}",
222        node00,
223        0f32,
224        layout.scroll_height()
225    );
226}