Replace per-node measure functions with a single measure function + per-node context (#490)
1#[test]
2fn grid_absolute_column_start() {
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 position: taffy::style::Position::Absolute,
9 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
10 inset: taffy::geometry::Rect {
11 left: taffy::style::LengthPercentageAuto::Length(4f32),
12 right: taffy::style::LengthPercentageAuto::Length(3f32),
13 top: taffy::style::LengthPercentageAuto::Length(1f32),
14 bottom: taffy::style::LengthPercentageAuto::Length(2f32),
15 },
16 ..Default::default()
17 })
18 .unwrap();
19 let node = taffy
20 .new_with_children(
21 taffy::style::Style {
22 display: taffy::style::Display::Grid,
23 grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
24 grid_template_columns: vec![length(40f32), length(40f32), length(40f32)],
25 padding: taffy::geometry::Rect {
26 left: taffy::style::LengthPercentage::Length(40f32),
27 right: taffy::style::LengthPercentage::Length(20f32),
28 top: taffy::style::LengthPercentage::Length(10f32),
29 bottom: taffy::style::LengthPercentage::Length(30f32),
30 },
31 ..Default::default()
32 },
33 &[node0],
34 )
35 .unwrap();
36 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
37 println!("\nComputed tree:");
38 taffy.print_tree(node);
39 println!();
40 let Layout { size, location, .. } = taffy.layout(node).unwrap();
41 assert_eq!(size.width, 180f32, "width of node {:?}. Expected {}. Actual {}", node, 180f32, size.width);
42 assert_eq!(size.height, 160f32, "height of node {:?}. Expected {}. Actual {}", node, 160f32, 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 { size, location, .. } = taffy.layout(node0).unwrap();
46 assert_eq!(size.width, 133f32, "width of node {:?}. Expected {}. Actual {}", node0, 133f32, size.width);
47 assert_eq!(size.height, 157f32, "height of node {:?}. Expected {}. Actual {}", node0, 157f32, size.height);
48 assert_eq!(location.x, 44f32, "x of node {:?}. Expected {}. Actual {}", node0, 44f32, location.x);
49 assert_eq!(location.y, 1f32, "y of node {:?}. Expected {}. Actual {}", node0, 1f32, location.y);
50}