gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 684HTML 640Markdown 12TOML 62290 Definiciones

⎇ 25571b5d07206880207e451af69dd3b49b113628 tests/generated/flex/display_none_fixed_size.rs Rust · 221 líneas · 8.7 KB Historia Quién tocó qué crudo

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

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