⎇ c9c40576df24056c2f0f8b421d8046d33bb1cc2d
tests/generated/grid/grid_percent_tracks_definite_overflow.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_percent_tracks_definite_overflow() {
3 #[allow(unused_imports)]
4 use taffy::{prelude::*, tree::Layout, Taffy};
5 let mut taffy: Taffy<crate::TextMeasure> = Taffy::new();
6 let node0 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
7 let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
8 let node2 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
9 let node3 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
10 let node4 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
11 let node5 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
12 let node = taffy
13 .new_with_children(
14 taffy::style::Style {
15 display: taffy::style::Display::Grid,
16 grid_template_rows: vec![percent(0.5f32), percent(0.8f32)],
17 grid_template_columns: vec![percent(0.4f32), percent(0.4f32), percent(0.4f32)],
18 size: taffy::geometry::Size {
19 width: taffy::style::Dimension::Length(120f32),
20 height: taffy::style::Dimension::Length(60f32),
21 },
22 ..Default::default()
23 },
24 &[node0, node1, node2, node3, node4, node5],
25 )
26 .unwrap();
27 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
28 println!("\nComputed tree:");
29 taffy.print_tree(node);
30 println!();
31 let Layout { size, location, .. } = taffy.layout(node).unwrap();
32 assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
33 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node, 60f32, size.height);
34 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
35 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
36 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
37 assert_eq!(size.width, 48f32, "width of node {:?}. Expected {}. Actual {}", node0, 48f32, size.width);
38 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node0, 30f32, size.height);
39 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
40 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
41 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
42 assert_eq!(size.width, 48f32, "width of node {:?}. Expected {}. Actual {}", node1, 48f32, size.width);
43 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node1, 30f32, size.height);
44 assert_eq!(location.x, 48f32, "x of node {:?}. Expected {}. Actual {}", node1, 48f32, location.x);
45 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
46 let Layout { size, location, .. } = taffy.layout(node2).unwrap();
47 assert_eq!(size.width, 48f32, "width of node {:?}. Expected {}. Actual {}", node2, 48f32, size.width);
48 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node2, 30f32, size.height);
49 assert_eq!(location.x, 96f32, "x of node {:?}. Expected {}. Actual {}", node2, 96f32, location.x);
50 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
51 let Layout { size, location, .. } = taffy.layout(node3).unwrap();
52 assert_eq!(size.width, 48f32, "width of node {:?}. Expected {}. Actual {}", node3, 48f32, size.width);
53 assert_eq!(size.height, 48f32, "height of node {:?}. Expected {}. Actual {}", node3, 48f32, size.height);
54 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
55 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node3, 30f32, location.y);
56 let Layout { size, location, .. } = taffy.layout(node4).unwrap();
57 assert_eq!(size.width, 48f32, "width of node {:?}. Expected {}. Actual {}", node4, 48f32, size.width);
58 assert_eq!(size.height, 48f32, "height of node {:?}. Expected {}. Actual {}", node4, 48f32, size.height);
59 assert_eq!(location.x, 48f32, "x of node {:?}. Expected {}. Actual {}", node4, 48f32, location.x);
60 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node4, 30f32, location.y);
61 let Layout { size, location, .. } = taffy.layout(node5).unwrap();
62 assert_eq!(size.width, 48f32, "width of node {:?}. Expected {}. Actual {}", node5, 48f32, size.width);
63 assert_eq!(size.height, 48f32, "height of node {:?}. Expected {}. Actual {}", node5, 48f32, size.height);
64 assert_eq!(location.x, 96f32, "x of node {:?}. Expected {}. Actual {}", node5, 96f32, location.x);
65 assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node5, 30f32, location.y);
66}