tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 9TOML 3CSS 1345 Definiciones

⎇ 40dd6120fc73aa866f30e52a51d1abaf39adce6f tests/generated/flex/align_baseline_child_margin.rs Rust · 187 líneas · 8.9 KB Historia Quién tocó qué crudo

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

1#[test]
2#[allow(non_snake_case)]
3fn align_baseline_child_margin__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            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::from_length(50f32),
11                height: taffy::style::Dimension::from_length(50f32),
12            },
13            margin: taffy::geometry::Rect {
14                left: length(5f32),
15                right: length(5f32),
16                top: length(5f32),
17                bottom: length(5f32),
18            },
19            ..Default::default()
20        })
21        .unwrap();
22    let node10 = taffy
23        .new_leaf(taffy::style::Style {
24            size: taffy::geometry::Size {
25                width: taffy::style::Dimension::from_length(50f32),
26                height: taffy::style::Dimension::from_length(10f32),
27            },
28            margin: taffy::geometry::Rect {
29                left: length(5f32),
30                right: length(5f32),
31                top: length(5f32),
32                bottom: length(5f32),
33            },
34            ..Default::default()
35        })
36        .unwrap();
37    let node1 = taffy
38        .new_with_children(
39            taffy::style::Style {
40                flex_direction: taffy::style::FlexDirection::Column,
41                size: taffy::geometry::Size {
42                    width: taffy::style::Dimension::from_length(50f32),
43                    height: taffy::style::Dimension::from_length(20f32),
44                },
45                ..Default::default()
46            },
47            &[node10],
48        )
49        .unwrap();
50    let node = taffy
51        .new_with_children(
52            taffy::style::Style {
53                align_items: Some(taffy::style::AlignItems::Baseline),
54                size: taffy::geometry::Size {
55                    width: taffy::style::Dimension::from_length(100f32),
56                    height: taffy::style::Dimension::from_length(100f32),
57                },
58                ..Default::default()
59            },
60            &[node0, node1],
61        )
62        .unwrap();
63    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
64    println!("\nComputed tree:");
65    taffy.print_tree(node);
66    println!();
67    let layout = taffy.layout(node).unwrap();
68    let Layout { size, location, .. } = layout;
69    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
70    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
71    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
72    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
73    let layout = taffy.layout(node0).unwrap();
74    let Layout { size, location, .. } = layout;
75    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
76    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
77    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x);
78    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
79    let layout = taffy.layout(node1).unwrap();
80    let Layout { size, location, .. } = layout;
81    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
82    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
83    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
84    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
85    let layout = taffy.layout(node10).unwrap();
86    let Layout { size, location, .. } = layout;
87    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
88    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
89    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node10, 5f32, location.x);
90    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node10, 5f32, location.y);
91}
92
93#[test]
94#[allow(non_snake_case)]
95fn align_baseline_child_margin__content_box() {
96    #[allow(unused_imports)]
97    use taffy::{prelude::*, Layout};
98    let mut taffy = crate::new_test_tree();
99    let node0 = taffy
100        .new_leaf(taffy::style::Style {
101            box_sizing: taffy::style::BoxSizing::ContentBox,
102            size: taffy::geometry::Size {
103                width: taffy::style::Dimension::from_length(50f32),
104                height: taffy::style::Dimension::from_length(50f32),
105            },
106            margin: taffy::geometry::Rect {
107                left: length(5f32),
108                right: length(5f32),
109                top: length(5f32),
110                bottom: length(5f32),
111            },
112            ..Default::default()
113        })
114        .unwrap();
115    let node10 = taffy
116        .new_leaf(taffy::style::Style {
117            box_sizing: taffy::style::BoxSizing::ContentBox,
118            size: taffy::geometry::Size {
119                width: taffy::style::Dimension::from_length(50f32),
120                height: taffy::style::Dimension::from_length(10f32),
121            },
122            margin: taffy::geometry::Rect {
123                left: length(5f32),
124                right: length(5f32),
125                top: length(5f32),
126                bottom: length(5f32),
127            },
128            ..Default::default()
129        })
130        .unwrap();
131    let node1 = taffy
132        .new_with_children(
133            taffy::style::Style {
134                box_sizing: taffy::style::BoxSizing::ContentBox,
135                flex_direction: taffy::style::FlexDirection::Column,
136                size: taffy::geometry::Size {
137                    width: taffy::style::Dimension::from_length(50f32),
138                    height: taffy::style::Dimension::from_length(20f32),
139                },
140                ..Default::default()
141            },
142            &[node10],
143        )
144        .unwrap();
145    let node = taffy
146        .new_with_children(
147            taffy::style::Style {
148                box_sizing: taffy::style::BoxSizing::ContentBox,
149                align_items: Some(taffy::style::AlignItems::Baseline),
150                size: taffy::geometry::Size {
151                    width: taffy::style::Dimension::from_length(100f32),
152                    height: taffy::style::Dimension::from_length(100f32),
153                },
154                ..Default::default()
155            },
156            &[node0, node1],
157        )
158        .unwrap();
159    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
160    println!("\nComputed tree:");
161    taffy.print_tree(node);
162    println!();
163    let layout = taffy.layout(node).unwrap();
164    let Layout { size, location, .. } = layout;
165    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
166    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
167    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
168    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
169    let layout = taffy.layout(node0).unwrap();
170    let Layout { size, location, .. } = layout;
171    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
172    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
173    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node0, 5f32, location.x);
174    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node0, 5f32, location.y);
175    let layout = taffy.layout(node1).unwrap();
176    let Layout { size, location, .. } = layout;
177    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
178    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
179    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
180    assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
181    let layout = taffy.layout(node10).unwrap();
182    let Layout { size, location, .. } = layout;
183    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
184    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
185    assert_eq!(location.x, 5f32, "x of node {:?}. Expected {}. Actual {}", node10, 5f32, location.x);
186    assert_eq!(location.y, 5f32, "y of node {:?}. Expected {}. Actual {}", node10, 5f32, location.y);
187}