⎇ 0.3.x
tests/generated/grid_span_2_max_content_max_content_indefinite.rs
History
Who touched what
raw
Grid: Fixes for minmax, fr proportions and distributing space across multiple tracks (#349)
1#[test]
2fn grid_span_2_max_content_max_content_indefinite() {
3 use slotmap::Key;
4 #[allow(unused_imports)]
5 use taffy::{layout::Layout, prelude::*};
6 let mut taffy = taffy::Taffy::new();
7 let node0 = taffy
8 .new_leaf(taffy::style::Style {
9 grid_row: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
10 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
11 ..Default::default()
12 })
13 .unwrap();
14 let node1 = taffy
15 .new_leaf(taffy::style::Style {
16 grid_row: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
17 grid_column: taffy::geometry::Line { start: line(2i16), end: taffy::style::GridPlacement::Auto },
18 ..Default::default()
19 })
20 .unwrap();
21 let node2 = taffy
22 .new_leaf_with_measure(
23 taffy::style::Style {
24 grid_row: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
25 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Span(2u16) },
26 ..Default::default()
27 },
28 taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
29 const TEXT: &str = "HHHH\u{200b}HHHH";
30 super::measure_standard_text(
31 known_dimensions,
32 available_space,
33 TEXT,
34 super::WritingMode::Horizontal,
35 None,
36 )
37 }),
38 )
39 .unwrap();
40 let node = taffy
41 .new_with_children(
42 taffy::style::Style {
43 display: taffy::style::Display::Grid,
44 grid_template_rows: vec![points(40f32)],
45 grid_template_columns: vec![max_content(), max_content()],
46 ..Default::default()
47 },
48 &[node0, node1, node2],
49 )
50 .unwrap();
51 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
52 println!("\nComputed tree:");
53 taffy::debug::print_tree(&taffy, node);
54 println!();
55 let Layout { size, location, .. } = taffy.layout(node).unwrap();
56 assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 80f32, size.width);
57 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 40f32, size.height);
58 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
59 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
60 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
61 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width);
62 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.height);
63 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
64 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
65 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
66 assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, size.width);
67 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, size.height);
68 assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, location.x);
69 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.y);
70 let Layout { size, location, .. } = taffy.layout(node2).unwrap();
71 assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 80f32, size.width);
72 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 40f32, size.height);
73 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.x);
74 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 0f32, location.y);
75}