tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81412 Definitions

⎇ 40dd6120fc73aa866f30e52a51d1abaf39adce6f tests/generated/flex/wrapped_row_within_align_items_flex_start.rs Rust · 154 lines · 7.8 KB History Who touched what raw

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

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