Replace per-node measure functions with a single measure function + per-node context (#490)
1#[test]
2fn grid_align_items_baseline_child() {
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(50f32),
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(50f32),
21 height: taffy::style::Dimension::Length(10f32),
22 },
23 ..Default::default()
24 })
25 .unwrap();
26 let node1 = taffy
27 .new_with_children(
28 taffy::style::Style {
29 display: taffy::style::Display::Grid,
30 size: taffy::geometry::Size {
31 width: taffy::style::Dimension::Length(50f32),
32 height: taffy::style::Dimension::Length(20f32),
33 },
34 ..Default::default()
35 },
36 &[node10],
37 )
38 .unwrap();
39 let node = taffy
40 .new_with_children(
41 taffy::style::Style {
42 display: taffy::style::Display::Grid,
43 align_items: Some(taffy::style::AlignItems::Baseline),
44 size: taffy::geometry::Size {
45 width: taffy::style::Dimension::Length(100f32),
46 height: taffy::style::Dimension::Length(100f32),
47 },
48 ..Default::default()
49 },
50 &[node0, node1],
51 )
52 .unwrap();
53 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
54 println!("\nComputed tree:");
55 taffy.print_tree(node);
56 println!();
57 let Layout { size, location, .. } = taffy.layout(node).unwrap();
58 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
59 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
60 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
61 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
62 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
63 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
64 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
65 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
66 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
67 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
68 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
69 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
70 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
71 assert_eq!(location.y, 65f32, "y of node {:?}. Expected {}. Actual {}", node1, 65f32, location.y);
72 let Layout { size, location, .. } = taffy.layout(node10).unwrap();
73 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
74 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
75 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
76 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
77}