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