tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Definitions

⎇ b746ac4f346dde8a2b6f85d3a428c02a2342f099 tests/generated/flex/min_width.rs Rust · 215 lines · 8.5 KB History Who touched what raw

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

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