⎇ 9958624168dfe671c82cbe3afb8ba6a7d35f7454
tests/generated/grid_available_space_greater_than_max_content.rs
Historia
Quién tocó qué
crudo
1#[test]
2fn grid_available_space_greater_than_max_content() {
3 #[allow(unused_imports)]
4 use taffy::{prelude::*, tree::Layout};
5 let mut taffy = taffy::Taffy::new();
6 let node0 = taffy
7 .new_leaf_with_measure(
8 taffy::style::Style { ..Default::default() },
9 taffy::tree::MeasureFunc::Raw(|known_dimensions, available_space| {
10 const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH";
11 super::measure_standard_text(
12 known_dimensions,
13 available_space,
14 TEXT,
15 super::WritingMode::Horizontal,
16 None,
17 )
18 }),
19 )
20 .unwrap();
21 let node1 = taffy
22 .new_leaf_with_measure(
23 taffy::style::Style { ..Default::default() },
24 taffy::tree::MeasureFunc::Raw(|known_dimensions, available_space| {
25 const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH";
26 super::measure_standard_text(
27 known_dimensions,
28 available_space,
29 TEXT,
30 super::WritingMode::Horizontal,
31 None,
32 )
33 }),
34 )
35 .unwrap();
36 let node = taffy
37 .new_with_children(
38 taffy::style::Style {
39 display: taffy::style::Display::Grid,
40 grid_template_columns: vec![auto(), auto()],
41 ..Default::default()
42 },
43 &[node0, node1],
44 )
45 .unwrap();
46 taffy
47 .compute_layout(
48 node,
49 taffy::geometry::Size {
50 width: taffy::style::AvailableSpace::Definite(400f32),
51 height: taffy::style::AvailableSpace::MaxContent,
52 },
53 )
54 .unwrap();
55 println!("\nComputed tree:");
56 taffy::util::print_tree(&taffy, node);
57 println!();
58 let Layout { size, location, .. } = taffy.layout(node).unwrap();
59 assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node, 160f32, size.width);
60 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node, 10f32, size.height);
61 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
62 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
63 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
64 assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node0, 80f32, size.width);
65 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
66 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
67 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
68 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
69 assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node1, 80f32, size.width);
70 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
71 assert_eq!(location.x, 80f32, "x of node {:?}. Expected {}. Actual {}", node1, 80f32, location.x);
72 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
73}