⎇ 2519aebad238d55fb767c2087344ccc99c21d1c6
tests/generated/grid/grid_justify_self_direction_rtl.rs
Historia
Quién tocó qué
crudo
add block layout & inherited fixtures, remove unused `flip` function
1#[test]
2#[allow(non_snake_case)]
3fn grid_justify_self_direction_rtl__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 justify_self: Some(taffy::style::JustifySelf::Start),
10 grid_row: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
11 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
12 size: taffy::geometry::Size {
13 width: taffy::style::Dimension::from_length(20f32),
14 height: taffy::style::Dimension::from_length(20f32),
15 },
16 ..Default::default()
17 })
18 .unwrap();
19 let node1 = taffy
20 .new_leaf(taffy::style::Style {
21 justify_self: Some(taffy::style::JustifySelf::End),
22 grid_row: taffy::geometry::Line { start: line(2i16), end: taffy::style::GridPlacement::Auto },
23 grid_column: taffy::geometry::Line { start: line(2i16), end: taffy::style::GridPlacement::Auto },
24 size: taffy::geometry::Size {
25 width: taffy::style::Dimension::from_length(20f32),
26 height: taffy::style::Dimension::from_length(20f32),
27 },
28 ..Default::default()
29 })
30 .unwrap();
31 let node2 = taffy
32 .new_leaf(taffy::style::Style {
33 justify_self: Some(taffy::style::JustifySelf::Center),
34 grid_row: taffy::geometry::Line { start: line(3i16), end: taffy::style::GridPlacement::Auto },
35 grid_column: taffy::geometry::Line { start: line(3i16), end: taffy::style::GridPlacement::Auto },
36 size: taffy::geometry::Size {
37 width: taffy::style::Dimension::from_length(20f32),
38 height: taffy::style::Dimension::from_length(20f32),
39 },
40 ..Default::default()
41 })
42 .unwrap();
43 let node = taffy
44 .new_with_children(
45 taffy::style::Style {
46 display: taffy::style::Display::Grid,
47 direction: taffy::style::Direction::Rtl,
48 grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
49 grid_template_columns: vec![length(40f32), length(40f32), length(40f32)],
50 size: taffy::geometry::Size {
51 width: taffy::style::Dimension::from_length(120f32),
52 height: taffy::style::Dimension::from_length(120f32),
53 },
54 ..Default::default()
55 },
56 &[node0, node1, node2],
57 )
58 .unwrap();
59 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
60 println!("\nComputed tree:");
61 taffy.print_tree(node);
62 println!();
63 let layout = taffy.layout(node).unwrap();
64 let Layout { size, location, .. } = layout;
65 assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
66 assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
67 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
68 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
69 let layout = taffy.layout(node0).unwrap();
70 let Layout { size, location, .. } = layout;
71 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
72 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
73 assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node0, 100f32, location.x);
74 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
75 let layout = taffy.layout(node1).unwrap();
76 let Layout { size, location, .. } = layout;
77 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
78 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
79 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1, 40f32, location.x);
80 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
81 let layout = taffy.layout(node2).unwrap();
82 let Layout { size, location, .. } = layout;
83 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
84 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
85 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node2, 10f32, location.x);
86 assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node2, 80f32, location.y);
87}
88
89#[test]
90#[allow(non_snake_case)]
91fn grid_justify_self_direction_rtl__content_box() {
92 #[allow(unused_imports)]
93 use taffy::{prelude::*, Layout};
94 let mut taffy = crate::new_test_tree();
95 let node0 = taffy
96 .new_leaf(taffy::style::Style {
97 box_sizing: taffy::style::BoxSizing::ContentBox,
98 justify_self: Some(taffy::style::JustifySelf::Start),
99 grid_row: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
100 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
101 size: taffy::geometry::Size {
102 width: taffy::style::Dimension::from_length(20f32),
103 height: taffy::style::Dimension::from_length(20f32),
104 },
105 ..Default::default()
106 })
107 .unwrap();
108 let node1 = taffy
109 .new_leaf(taffy::style::Style {
110 box_sizing: taffy::style::BoxSizing::ContentBox,
111 justify_self: Some(taffy::style::JustifySelf::End),
112 grid_row: taffy::geometry::Line { start: line(2i16), end: taffy::style::GridPlacement::Auto },
113 grid_column: taffy::geometry::Line { start: line(2i16), end: taffy::style::GridPlacement::Auto },
114 size: taffy::geometry::Size {
115 width: taffy::style::Dimension::from_length(20f32),
116 height: taffy::style::Dimension::from_length(20f32),
117 },
118 ..Default::default()
119 })
120 .unwrap();
121 let node2 = taffy
122 .new_leaf(taffy::style::Style {
123 box_sizing: taffy::style::BoxSizing::ContentBox,
124 justify_self: Some(taffy::style::JustifySelf::Center),
125 grid_row: taffy::geometry::Line { start: line(3i16), end: taffy::style::GridPlacement::Auto },
126 grid_column: taffy::geometry::Line { start: line(3i16), end: taffy::style::GridPlacement::Auto },
127 size: taffy::geometry::Size {
128 width: taffy::style::Dimension::from_length(20f32),
129 height: taffy::style::Dimension::from_length(20f32),
130 },
131 ..Default::default()
132 })
133 .unwrap();
134 let node = taffy
135 .new_with_children(
136 taffy::style::Style {
137 display: taffy::style::Display::Grid,
138 box_sizing: taffy::style::BoxSizing::ContentBox,
139 direction: taffy::style::Direction::Rtl,
140 grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
141 grid_template_columns: vec![length(40f32), length(40f32), length(40f32)],
142 size: taffy::geometry::Size {
143 width: taffy::style::Dimension::from_length(120f32),
144 height: taffy::style::Dimension::from_length(120f32),
145 },
146 ..Default::default()
147 },
148 &[node0, node1, node2],
149 )
150 .unwrap();
151 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
152 println!("\nComputed tree:");
153 taffy.print_tree(node);
154 println!();
155 let layout = taffy.layout(node).unwrap();
156 let Layout { size, location, .. } = layout;
157 assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
158 assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
159 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
160 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
161 let layout = taffy.layout(node0).unwrap();
162 let Layout { size, location, .. } = layout;
163 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
164 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
165 assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node0, 100f32, location.x);
166 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
167 let layout = taffy.layout(node1).unwrap();
168 let Layout { size, location, .. } = layout;
169 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
170 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
171 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1, 40f32, location.x);
172 assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1, 40f32, location.y);
173 let layout = taffy.layout(node2).unwrap();
174 let Layout { size, location, .. } = layout;
175 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node2, 20f32, size.width);
176 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node2, 20f32, size.height);
177 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node2, 10f32, location.x);
178 assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node2, 80f32, location.y);
179}