⎇ float-layout
tests/generated/grid/grid_auto_fit_with_empty_auto_track.rs
Historia
Quién tocó qué
crudo
CSS Grid: named lines and areas (#840)
1#[test]
2#[allow(non_snake_case)]
3fn grid_auto_fit_with_empty_auto_track__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node0 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
8 let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
9 let node = taffy
10 .new_with_children(
11 taffy::style::Style {
12 display: taffy::style::Display::Grid,
13 justify_content: Some(taffy::style::JustifyContent::SpaceEvenly),
14 grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
15 grid_template_columns: vec![repeat(RepetitionCount::AutoFit, vec![length(40f32)])],
16 size: taffy::geometry::Size {
17 width: taffy::style::Dimension::from_length(120f32),
18 height: taffy::style::Dimension::from_length(120f32),
19 },
20 ..Default::default()
21 },
22 &[node0, node1],
23 )
24 .unwrap();
25 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
26 println!("\nComputed tree:");
27 taffy.print_tree(node);
28 println!();
29 let layout = taffy.layout(node).unwrap();
30 let Layout { size, location, .. } = layout;
31 assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
32 assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
33 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
34 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
35 let layout = taffy.layout(node0).unwrap();
36 let Layout { size, location, .. } = layout;
37 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
38 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
39 assert_eq!(location.x, 13f32, "x of node {:?}. Expected {}. Actual {}", node0, 13f32, location.x);
40 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
41 let layout = taffy.layout(node1).unwrap();
42 let Layout { size, location, .. } = layout;
43 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
44 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
45 assert_eq!(location.x, 67f32, "x of node {:?}. Expected {}. Actual {}", node1, 67f32, location.x);
46 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
47}
48
49#[test]
50#[allow(non_snake_case)]
51fn grid_auto_fit_with_empty_auto_track__content_box() {
52 #[allow(unused_imports)]
53 use taffy::{prelude::*, Layout};
54 let mut taffy = crate::new_test_tree();
55 let node0 = taffy
56 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
57 .unwrap();
58 let node1 = taffy
59 .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
60 .unwrap();
61 let node = taffy
62 .new_with_children(
63 taffy::style::Style {
64 display: taffy::style::Display::Grid,
65 box_sizing: taffy::style::BoxSizing::ContentBox,
66 justify_content: Some(taffy::style::JustifyContent::SpaceEvenly),
67 grid_template_rows: vec![length(40f32), length(40f32), length(40f32)],
68 grid_template_columns: vec![repeat(RepetitionCount::AutoFit, vec![length(40f32)])],
69 size: taffy::geometry::Size {
70 width: taffy::style::Dimension::from_length(120f32),
71 height: taffy::style::Dimension::from_length(120f32),
72 },
73 ..Default::default()
74 },
75 &[node0, node1],
76 )
77 .unwrap();
78 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
79 println!("\nComputed tree:");
80 taffy.print_tree(node);
81 println!();
82 let layout = taffy.layout(node).unwrap();
83 let Layout { size, location, .. } = layout;
84 assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node, 120f32, size.width);
85 assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
86 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
87 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
88 let layout = taffy.layout(node0).unwrap();
89 let Layout { size, location, .. } = layout;
90 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
91 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
92 assert_eq!(location.x, 13f32, "x of node {:?}. Expected {}. Actual {}", node0, 13f32, location.x);
93 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
94 let layout = taffy.layout(node1).unwrap();
95 let Layout { size, location, .. } = layout;
96 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
97 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
98 assert_eq!(location.x, 67f32, "x of node {:?}. Expected {}. Actual {}", node1, 67f32, location.x);
99 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
100}