tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Sutichaykuna

⎇ float-layout tests/generated/grid/grid_available_space_smaller_than_max_content.rs Rust · 122 siq'ikuna · 6.0 KB Ñawpa willay Pi imata llamkarqan ch'uya

Add `taffy_test_helpers` crate (#755) 2a3e8476b · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn grid_available_space_smaller_than_max_content__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node0 = taffy
8        .new_leaf_with_context(
9            taffy::style::Style { ..Default::default() },
10            crate::TestNodeContext::ahem_text("HH\u{200b}HH\u{200b}HH\u{200b}HH", crate::WritingMode::Horizontal),
11        )
12        .unwrap();
13    let node1 = taffy
14        .new_leaf_with_context(
15            taffy::style::Style { ..Default::default() },
16            crate::TestNodeContext::ahem_text("HH\u{200b}HH\u{200b}HH\u{200b}HH", crate::WritingMode::Horizontal),
17        )
18        .unwrap();
19    let node = taffy
20        .new_with_children(
21            taffy::style::Style {
22                display: taffy::style::Display::Grid,
23                grid_template_columns: vec![auto(), auto()],
24                ..Default::default()
25            },
26            &[node0, node1],
27        )
28        .unwrap();
29    taffy
30        .compute_layout_with_measure(
31            node,
32            taffy::geometry::Size {
33                width: taffy::style::AvailableSpace::Definite(80f32),
34                height: taffy::style::AvailableSpace::MaxContent,
35            },
36            crate::test_measure_function,
37        )
38        .unwrap();
39    println!("\nComputed tree:");
40    taffy.print_tree(node);
41    println!();
42    let layout = taffy.layout(node).unwrap();
43    let Layout { size, location, .. } = layout;
44    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node, 80f32, size.width);
45    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
46    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
47    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
48    let layout = taffy.layout(node0).unwrap();
49    let Layout { size, location, .. } = layout;
50    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
51    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
52    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
53    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
54    let layout = taffy.layout(node1).unwrap();
55    let Layout { size, location, .. } = layout;
56    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
57    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
58    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1, 40f32, location.x);
59    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
60}
61
62#[test]
63#[allow(non_snake_case)]
64fn grid_available_space_smaller_than_max_content__content_box() {
65    #[allow(unused_imports)]
66    use taffy::{prelude::*, Layout};
67    let mut taffy = crate::new_test_tree();
68    let node0 = taffy
69        .new_leaf_with_context(
70            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
71            crate::TestNodeContext::ahem_text("HH\u{200b}HH\u{200b}HH\u{200b}HH", crate::WritingMode::Horizontal),
72        )
73        .unwrap();
74    let node1 = taffy
75        .new_leaf_with_context(
76            taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
77            crate::TestNodeContext::ahem_text("HH\u{200b}HH\u{200b}HH\u{200b}HH", crate::WritingMode::Horizontal),
78        )
79        .unwrap();
80    let node = taffy
81        .new_with_children(
82            taffy::style::Style {
83                display: taffy::style::Display::Grid,
84                box_sizing: taffy::style::BoxSizing::ContentBox,
85                grid_template_columns: vec![auto(), auto()],
86                ..Default::default()
87            },
88            &[node0, node1],
89        )
90        .unwrap();
91    taffy
92        .compute_layout_with_measure(
93            node,
94            taffy::geometry::Size {
95                width: taffy::style::AvailableSpace::Definite(80f32),
96                height: taffy::style::AvailableSpace::MaxContent,
97            },
98            crate::test_measure_function,
99        )
100        .unwrap();
101    println!("\nComputed tree:");
102    taffy.print_tree(node);
103    println!();
104    let layout = taffy.layout(node).unwrap();
105    let Layout { size, location, .. } = layout;
106    assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node, 80f32, size.width);
107    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
108    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
109    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
110    let layout = taffy.layout(node0).unwrap();
111    let Layout { size, location, .. } = layout;
112    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
113    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
114    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
115    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
116    let layout = taffy.layout(node1).unwrap();
117    let Layout { size, location, .. } = layout;
118    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
119    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
120    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1, 40f32, location.x);
121    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
122}