⎇ c9c40576df24056c2f0f8b421d8046d33bb1cc2d
tests/generated/grid/grid_align_items_baseline_child_multiline_override.rs
Historia
Quién tocó qué
crudo
Replace per-node measure functions with a single measure function + per-node context (#490)
1#[test]
2fn grid_align_items_baseline_child_multiline_override() {
3 #[allow(unused_imports)]
4 use taffy::{prelude::*, tree::Layout, Taffy};
5 let mut taffy: Taffy<crate::TextMeasure> = Taffy::new();
6 let node0 = taffy
7 .new_leaf(taffy::style::Style {
8 display: taffy::style::Display::Grid,
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::Length(50f32),
11 height: taffy::style::Dimension::Length(60f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node10 = taffy
17 .new_leaf(taffy::style::Style {
18 display: taffy::style::Display::Grid,
19 size: taffy::geometry::Size {
20 width: taffy::style::Dimension::Length(25f32),
21 height: taffy::style::Dimension::Length(20f32),
22 },
23 ..Default::default()
24 })
25 .unwrap();
26 let node11 = taffy
27 .new_leaf(taffy::style::Style {
28 display: taffy::style::Display::Grid,
29 align_self: Some(taffy::style::AlignSelf::Baseline),
30 size: taffy::geometry::Size {
31 width: taffy::style::Dimension::Length(25f32),
32 height: taffy::style::Dimension::Length(10f32),
33 },
34 ..Default::default()
35 })
36 .unwrap();
37 let node12 = taffy
38 .new_leaf(taffy::style::Style {
39 display: taffy::style::Display::Grid,
40 size: taffy::geometry::Size {
41 width: taffy::style::Dimension::Length(25f32),
42 height: taffy::style::Dimension::Length(20f32),
43 },
44 ..Default::default()
45 })
46 .unwrap();
47 let node13 = taffy
48 .new_leaf(taffy::style::Style {
49 display: taffy::style::Display::Grid,
50 align_self: Some(taffy::style::AlignSelf::Baseline),
51 size: taffy::geometry::Size {
52 width: taffy::style::Dimension::Length(25f32),
53 height: taffy::style::Dimension::Length(10f32),
54 },
55 ..Default::default()
56 })
57 .unwrap();
58 let node1 = taffy
59 .new_with_children(
60 taffy::style::Style {
61 display: taffy::style::Display::Grid,
62 grid_template_columns: vec![auto(), auto()],
63 size: taffy::geometry::Size {
64 width: taffy::style::Dimension::Length(50f32),
65 height: taffy::style::Dimension::Length(25f32),
66 },
67 ..Default::default()
68 },
69 &[node10, node11, node12, node13],
70 )
71 .unwrap();
72 let node = taffy
73 .new_with_children(
74 taffy::style::Style {
75 display: taffy::style::Display::Grid,
76 align_items: Some(taffy::style::AlignItems::Baseline),
77 size: taffy::geometry::Size {
78 width: taffy::style::Dimension::Length(100f32),
79 height: taffy::style::Dimension::Length(100f32),
80 },
81 ..Default::default()
82 },
83 &[node0, node1],
84 )
85 .unwrap();
86 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
87 println!("\nComputed tree:");
88 taffy.print_tree(node);
89 println!();
90 let Layout { size, location, .. } = taffy.layout(node).unwrap();
91 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
92 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
93 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
94 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
95 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
96 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
97 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node0, 60f32, size.height);
98 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
99 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
100 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
101 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
102 assert_eq!(size.height, 25f32, "height of node {:?}. Expected {}. Actual {}", node1, 25f32, size.height);
103 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
104 assert_eq!(location.y, 68f32, "y of node {:?}. Expected {}. Actual {}", node1, 68f32, location.y);
105 let Layout { size, location, .. } = taffy.layout(node10).unwrap();
106 assert_eq!(size.width, 25f32, "width of node {:?}. Expected {}. Actual {}", node10, 25f32, size.width);
107 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node10, 20f32, size.height);
108 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
109 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
110 let Layout { size, location, .. } = taffy.layout(node11).unwrap();
111 assert_eq!(size.width, 25f32, "width of node {:?}. Expected {}. Actual {}", node11, 25f32, size.width);
112 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node11, 10f32, size.height);
113 assert_eq!(location.x, 25f32, "x of node {:?}. Expected {}. Actual {}", node11, 25f32, location.x);
114 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node11, 0f32, location.y);
115 let Layout { size, location, .. } = taffy.layout(node12).unwrap();
116 assert_eq!(size.width, 25f32, "width of node {:?}. Expected {}. Actual {}", node12, 25f32, size.width);
117 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node12, 20f32, size.height);
118 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node12, 0f32, location.x);
119 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node12, 20f32, location.y);
120 let Layout { size, location, .. } = taffy.layout(node13).unwrap();
121 assert_eq!(size.width, 25f32, "width of node {:?}. Expected {}. Actual {}", node13, 25f32, size.width);
122 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node13, 10f32, size.height);
123 assert_eq!(location.x, 25f32, "x of node {:?}. Expected {}. Actual {}", node13, 25f32, location.x);
124 assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node13, 20f32, location.y);
125}