tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 229Rust 8TOML 3CSS 1310 Sutichaykuna

⎇ direction-floats tests/generated/flex/flex_shrink_to_zero.rs Rust · 153 siq'ikuna · 7.7 KB Ñawpa willay Pi imata llamkarqan ch'uya

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn flex_shrink_to_zero__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node0 = taffy
8        .new_leaf(taffy::style::Style {
9            flex_shrink: 0f32,
10            size: taffy::geometry::Size {
11                width: taffy::style::Dimension::from_length(50f32),
12                height: taffy::style::Dimension::from_length(50f32),
13            },
14            ..Default::default()
15        })
16        .unwrap();
17    let node1 = taffy
18        .new_leaf(taffy::style::Style {
19            flex_shrink: 1f32,
20            size: taffy::geometry::Size {
21                width: taffy::style::Dimension::from_length(50f32),
22                height: taffy::style::Dimension::from_length(50f32),
23            },
24            ..Default::default()
25        })
26        .unwrap();
27    let node2 = taffy
28        .new_leaf(taffy::style::Style {
29            flex_shrink: 0f32,
30            size: taffy::geometry::Size {
31                width: taffy::style::Dimension::from_length(50f32),
32                height: taffy::style::Dimension::from_length(50f32),
33            },
34            ..Default::default()
35        })
36        .unwrap();
37    let node = taffy
38        .new_with_children(
39            taffy::style::Style {
40                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(75f32), height: auto() },
41                ..Default::default()
42            },
43            &[node0, node1, node2],
44        )
45        .unwrap();
46    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
47    println!("\nComputed tree:");
48    taffy.print_tree(node);
49    println!();
50    let layout = taffy.layout(node).unwrap();
51    let Layout { size, location, .. } = layout;
52    assert_eq!(size.width, 75f32, "width of node {:?}. Expected {}. Actual {}", node, 75f32, size.width);
53    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
54    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
55    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
56    let layout = taffy.layout(node0).unwrap();
57    let Layout { size, location, .. } = layout;
58    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
59    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
60    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
61    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
62    let layout = taffy.layout(node1).unwrap();
63    let Layout { size, location, .. } = layout;
64    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node1, 0f32, size.width);
65    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
66    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
67    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
68    let layout = taffy.layout(node2).unwrap();
69    let Layout { size, location, .. } = layout;
70    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
71    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2, 50f32, size.height);
72    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node2, 50f32, location.x);
73    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
74}
75
76#[test]
77#[allow(non_snake_case)]
78fn flex_shrink_to_zero__content_box() {
79    #[allow(unused_imports)]
80    use taffy::{prelude::*, Layout};
81    let mut taffy = crate::new_test_tree();
82    let node0 = taffy
83        .new_leaf(taffy::style::Style {
84            box_sizing: taffy::style::BoxSizing::ContentBox,
85            flex_shrink: 0f32,
86            size: taffy::geometry::Size {
87                width: taffy::style::Dimension::from_length(50f32),
88                height: taffy::style::Dimension::from_length(50f32),
89            },
90            ..Default::default()
91        })
92        .unwrap();
93    let node1 = taffy
94        .new_leaf(taffy::style::Style {
95            box_sizing: taffy::style::BoxSizing::ContentBox,
96            flex_shrink: 1f32,
97            size: taffy::geometry::Size {
98                width: taffy::style::Dimension::from_length(50f32),
99                height: taffy::style::Dimension::from_length(50f32),
100            },
101            ..Default::default()
102        })
103        .unwrap();
104    let node2 = taffy
105        .new_leaf(taffy::style::Style {
106            box_sizing: taffy::style::BoxSizing::ContentBox,
107            flex_shrink: 0f32,
108            size: taffy::geometry::Size {
109                width: taffy::style::Dimension::from_length(50f32),
110                height: taffy::style::Dimension::from_length(50f32),
111            },
112            ..Default::default()
113        })
114        .unwrap();
115    let node = taffy
116        .new_with_children(
117            taffy::style::Style {
118                box_sizing: taffy::style::BoxSizing::ContentBox,
119                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(75f32), height: auto() },
120                ..Default::default()
121            },
122            &[node0, node1, node2],
123        )
124        .unwrap();
125    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
126    println!("\nComputed tree:");
127    taffy.print_tree(node);
128    println!();
129    let layout = taffy.layout(node).unwrap();
130    let Layout { size, location, .. } = layout;
131    assert_eq!(size.width, 75f32, "width of node {:?}. Expected {}. Actual {}", node, 75f32, size.width);
132    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
133    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
134    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
135    let layout = taffy.layout(node0).unwrap();
136    let Layout { size, location, .. } = layout;
137    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
138    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
139    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
140    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
141    let layout = taffy.layout(node1).unwrap();
142    let Layout { size, location, .. } = layout;
143    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node1, 0f32, size.width);
144    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
145    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
146    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
147    let layout = taffy.layout(node2).unwrap();
148    let Layout { size, location, .. } = layout;
149    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
150    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2, 50f32, size.height);
151    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node2, 50f32, location.x);
152    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
153}