Replace per-node measure functions with a single measure function + per-node context (#490)
1#[test]
2fn blockflex_block_in_flex_column() {
3 #[allow(unused_imports)]
4 use taffy::{prelude::*, tree::Layout, Taffy};
5 let mut taffy: Taffy<crate::TextMeasure> = Taffy::new();
6 let node0 =
7 taffy.new_leaf(taffy::style::Style { display: taffy::style::Display::Block, ..Default::default() }).unwrap();
8 let node1 = taffy
9 .new_leaf(taffy::style::Style {
10 display: taffy::style::Display::Block,
11 size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
12 ..Default::default()
13 })
14 .unwrap();
15 let node = taffy
16 .new_with_children(
17 taffy::style::Style {
18 display: taffy::style::Display::Flex,
19 flex_direction: taffy::style::FlexDirection::Column,
20 size: taffy::geometry::Size {
21 width: taffy::style::Dimension::Length(200f32),
22 height: taffy::style::Dimension::Length(50f32),
23 },
24 ..Default::default()
25 },
26 &[node0, node1],
27 )
28 .unwrap();
29 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
30 println!("\nComputed tree:");
31 taffy.print_tree(node);
32 println!();
33 let Layout { size, location, .. } = taffy.layout(node).unwrap();
34 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
35 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
36 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
37 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
38 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
39 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
40 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node0, 0f32, size.height);
41 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
42 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
43 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
44 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
45 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node1, 0f32, size.height);
46 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
47 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
48}