⎇ float-layout
tests/generated/flex/margin_auto_left_child_bigger_than_parent.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn margin_auto_left_child_bigger_than_parent__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(72f32),
11 height: taffy::style::Dimension::from_length(72f32),
12 },
13 margin: taffy::geometry::Rect {
14 left: taffy::style::LengthPercentageAuto::AUTO,
15 right: zero(),
16 top: zero(),
17 bottom: zero(),
18 },
19 ..Default::default()
20 })
21 .unwrap();
22 let node = taffy
23 .new_with_children(
24 taffy::style::Style {
25 justify_content: Some(taffy::style::JustifyContent::Center),
26 size: taffy::geometry::Size {
27 width: taffy::style::Dimension::from_length(52f32),
28 height: taffy::style::Dimension::from_length(52f32),
29 },
30 ..Default::default()
31 },
32 &[node0],
33 )
34 .unwrap();
35 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
36 println!("\nComputed tree:");
37 taffy.print_tree(node);
38 println!();
39 let layout = taffy.layout(node).unwrap();
40 let Layout { size, location, .. } = layout;
41 assert_eq!(size.width, 52f32, "width of node {:?}. Expected {}. Actual {}", node, 52f32, size.width);
42 assert_eq!(size.height, 52f32, "height of node {:?}. Expected {}. Actual {}", node, 52f32, size.height);
43 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
44 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
45 let layout = taffy.layout(node0).unwrap();
46 let Layout { size, location, .. } = layout;
47 assert_eq!(size.width, 52f32, "width of node {:?}. Expected {}. Actual {}", node0, 52f32, size.width);
48 assert_eq!(size.height, 72f32, "height of node {:?}. Expected {}. Actual {}", node0, 72f32, size.height);
49 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
50 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
51}
52
53#[test]
54#[allow(non_snake_case)]
55fn margin_auto_left_child_bigger_than_parent__content_box() {
56 #[allow(unused_imports)]
57 use taffy::{prelude::*, Layout};
58 let mut taffy = crate::new_test_tree();
59 let node0 = taffy
60 .new_leaf(taffy::style::Style {
61 box_sizing: taffy::style::BoxSizing::ContentBox,
62 size: taffy::geometry::Size {
63 width: taffy::style::Dimension::from_length(72f32),
64 height: taffy::style::Dimension::from_length(72f32),
65 },
66 margin: taffy::geometry::Rect {
67 left: taffy::style::LengthPercentageAuto::AUTO,
68 right: zero(),
69 top: zero(),
70 bottom: zero(),
71 },
72 ..Default::default()
73 })
74 .unwrap();
75 let node = taffy
76 .new_with_children(
77 taffy::style::Style {
78 box_sizing: taffy::style::BoxSizing::ContentBox,
79 justify_content: Some(taffy::style::JustifyContent::Center),
80 size: taffy::geometry::Size {
81 width: taffy::style::Dimension::from_length(52f32),
82 height: taffy::style::Dimension::from_length(52f32),
83 },
84 ..Default::default()
85 },
86 &[node0],
87 )
88 .unwrap();
89 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
90 println!("\nComputed tree:");
91 taffy.print_tree(node);
92 println!();
93 let layout = taffy.layout(node).unwrap();
94 let Layout { size, location, .. } = layout;
95 assert_eq!(size.width, 52f32, "width of node {:?}. Expected {}. Actual {}", node, 52f32, size.width);
96 assert_eq!(size.height, 52f32, "height of node {:?}. Expected {}. Actual {}", node, 52f32, size.height);
97 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
98 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
99 let layout = taffy.layout(node0).unwrap();
100 let Layout { size, location, .. } = layout;
101 assert_eq!(size.width, 52f32, "width of node {:?}. Expected {}. Actual {}", node0, 52f32, size.width);
102 assert_eq!(size.height, 72f32, "height of node {:?}. Expected {}. Actual {}", node0, 72f32, size.height);
103 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
104 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
105}