tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Definiciones

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