tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 10TOML 3CSS 1348 Definitions

⎇ 3bc35ec3b541eea8ea62344722f155ce9b22e227 tests/generated/flex/flex_grow_within_constrained_max_column.rs Rust · 218 lines · 8.9 KB History Who touched what raw

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

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