tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5334Rust 85Markdown 12TOML 91813 Definitions

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