⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2
tests/generated/grid/grid_justify_items_sized_start.rs
Historia
Quién tocó qué
crudo
Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn grid_justify_items_sized_start__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 grid_row: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
10 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
11 size: taffy::geometry::Size {
12 width: taffy::style::Dimension::from_length(20f32),
13 height: taffy::style::Dimension::from_length(20f32),
14 },
15 ..Default::default()
16 })
17 .unwrap();
18 let node1 = taffy
19 .new_leaf(taffy::style::Style {
20 grid_row: taffy::geometry::Line { start: line(3i16), end: taffy::style::GridPlacement::Auto },
21 grid_column: taffy::geometry::Line { start: line(3i16), end: taffy::style::GridPlacement::Auto },
22 size: taffy::geometry::Size {
23 width: taffy::style::Dimension::from_length(60f32),
24 height: taffy::style::Dimension::from_length(60f32),
25 },
26 ..Default::default()
27 })
28 .unwrap();
29 let node = taffy
30 .new_with_children(
31 taffy::style::Style {
32 display: taffy::style::Display::Grid,
33 justify_items: Some(taffy::style::JustifyItems::Start),
34 grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
35 grid_template_columns: vec![length(40f32), length(40f32), length(40f32)],
36 size: taffy::geometry::Size {
37 width: taffy::style::Dimension::from_length(120f32),
38 height: taffy::style::Dimension::from_length(120f32),
39 },
40 ..Default::default()
41 },
42 &[node0, node1],
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, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
52 assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, 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, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
58 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, 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(node1).unwrap();
62 let Layout { size, location, .. } = layout;
63 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node1, 60f32, size.width);
64 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node1, 60f32, size.height);
65 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node1, 80f32, location.x);
66 assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node1, 80f32, location.y);
67}
68
69#[test]
70#[allow(non_snake_case)]
71fn grid_justify_items_sized_start__content_box() {
72 #[allow(unused_imports)]
73 use taffy::{prelude::*, Layout};
74 let mut taffy = crate::new_test_tree();
75 let node0 = taffy
76 .new_leaf(taffy::style::Style {
77 box_sizing: taffy::style::BoxSizing::ContentBox,
78 grid_row: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
79 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
80 size: taffy::geometry::Size {
81 width: taffy::style::Dimension::from_length(20f32),
82 height: taffy::style::Dimension::from_length(20f32),
83 },
84 ..Default::default()
85 })
86 .unwrap();
87 let node1 = taffy
88 .new_leaf(taffy::style::Style {
89 box_sizing: taffy::style::BoxSizing::ContentBox,
90 grid_row: taffy::geometry::Line { start: line(3i16), end: taffy::style::GridPlacement::Auto },
91 grid_column: taffy::geometry::Line { start: line(3i16), end: taffy::style::GridPlacement::Auto },
92 size: taffy::geometry::Size {
93 width: taffy::style::Dimension::from_length(60f32),
94 height: taffy::style::Dimension::from_length(60f32),
95 },
96 ..Default::default()
97 })
98 .unwrap();
99 let node = taffy
100 .new_with_children(
101 taffy::style::Style {
102 display: taffy::style::Display::Grid,
103 box_sizing: taffy::style::BoxSizing::ContentBox,
104 justify_items: Some(taffy::style::JustifyItems::Start),
105 grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
106 grid_template_columns: vec![length(40f32), length(40f32), length(40f32)],
107 size: taffy::geometry::Size {
108 width: taffy::style::Dimension::from_length(120f32),
109 height: taffy::style::Dimension::from_length(120f32),
110 },
111 ..Default::default()
112 },
113 &[node0, node1],
114 )
115 .unwrap();
116 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
117 println!("\nComputed tree:");
118 taffy.print_tree(node);
119 println!();
120 let layout = taffy.layout(node).unwrap();
121 let Layout { size, location, .. } = layout;
122 assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
123 assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
124 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
125 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
126 let layout = taffy.layout(node0).unwrap();
127 let Layout { size, location, .. } = layout;
128 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
129 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
130 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
131 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
132 let layout = taffy.layout(node1).unwrap();
133 let Layout { size, location, .. } = layout;
134 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node1, 60f32, size.width);
135 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node1, 60f32, size.height);
136 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node1, 80f32, location.x);
137 assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node1, 80f32, location.y);
138}