⎇ 0.3.x
tests/generated/grid_available_space_greater_than_max_content.rs
History
Who touched what
raw
1#[test]
2fn grid_available_space_greater_than_max_content() {
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_with_measure(
9 taffy::style::Style { ..Default::default() },
10 taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
11 const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH";
12 super::measure_standard_text(
13 known_dimensions,
14 available_space,
15 TEXT,
16 super::WritingMode::Horizontal,
17 None,
18 )
19 }),
20 )
21 .unwrap();
22 let node1 = taffy
23 .new_leaf_with_measure(
24 taffy::style::Style { ..Default::default() },
25 taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
26 const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH";
27 super::measure_standard_text(
28 known_dimensions,
29 available_space,
30 TEXT,
31 super::WritingMode::Horizontal,
32 None,
33 )
34 }),
35 )
36 .unwrap();
37 let node = taffy
38 .new_with_children(
39 taffy::style::Style {
40 display: taffy::style::Display::Grid,
41 grid_template_columns: vec![auto(), auto()],
42 ..Default::default()
43 },
44 &[node0, node1],
45 )
46 .unwrap();
47 taffy
48 .compute_layout(
49 node,
50 taffy::geometry::Size {
51 width: taffy::style::AvailableSpace::Definite(400f32),
52 height: taffy::style::AvailableSpace::MaxContent,
53 },
54 )
55 .unwrap();
56 println!("\nComputed tree:");
57 taffy::debug::print_tree(&taffy, node);
58 println!();
59 let Layout { size, location, .. } = taffy.layout(node).unwrap();
60 assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 160f32, size.width);
61 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 10f32, size.height);
62 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
63 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
64 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
65 assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 80f32, size.width);
66 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, size.height);
67 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
68 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
69 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
70 assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 80f32, size.width);
71 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 10f32, size.height);
72 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 80f32, location.x);
73 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.y);
74}