tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 709HTML 662Markdown 12TOML 62348 Sutichaykuna

⎇ float-layout tests/generated/block/block_absolute_aspect_ratio_fill_max_height.rs Rust · 103 siq'ikuna · 5.0 KB Ñawpa willay Pi imata llamkarqan ch'uya

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn block_absolute_aspect_ratio_fill_max_height__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 {
10                position: taffy::style::Position::Absolute,
11                max_size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
12                aspect_ratio: Some(3f32),
13                ..Default::default()
14            },
15            crate::TestNodeContext::ahem_text(
16                "HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH",
17                crate::WritingMode::Horizontal,
18            ),
19        )
20        .unwrap();
21    let node = taffy
22        .new_with_children(
23            taffy::style::Style {
24                display: taffy::style::Display::Block,
25                size: taffy::geometry::Size {
26                    width: taffy::style::Dimension::from_length(400f32),
27                    height: taffy::style::Dimension::from_length(300f32),
28                },
29                ..Default::default()
30            },
31            &[node0],
32        )
33        .unwrap();
34    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
35    println!("\nComputed tree:");
36    taffy.print_tree(node);
37    println!();
38    let layout = taffy.layout(node).unwrap();
39    let Layout { size, location, .. } = layout;
40    assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node, 400f32, size.width);
41    assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node, 300f32, size.height);
42    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
43    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
44    let layout = taffy.layout(node0).unwrap();
45    let Layout { size, location, .. } = layout;
46    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
47    assert_eq!(size.height, 17f32, "height of node {:?}. Expected {}. Actual {}", node0, 17f32, size.height);
48    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
49    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
50}
51
52#[test]
53#[allow(non_snake_case)]
54fn block_absolute_aspect_ratio_fill_max_height__content_box() {
55    #[allow(unused_imports)]
56    use taffy::{prelude::*, Layout};
57    let mut taffy = crate::new_test_tree();
58    let node0 = taffy
59        .new_leaf_with_context(
60            taffy::style::Style {
61                box_sizing: taffy::style::BoxSizing::ContentBox,
62                position: taffy::style::Position::Absolute,
63                max_size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
64                aspect_ratio: Some(3f32),
65                ..Default::default()
66            },
67            crate::TestNodeContext::ahem_text(
68                "HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH",
69                crate::WritingMode::Horizontal,
70            ),
71        )
72        .unwrap();
73    let node = taffy
74        .new_with_children(
75            taffy::style::Style {
76                display: taffy::style::Display::Block,
77                box_sizing: taffy::style::BoxSizing::ContentBox,
78                size: taffy::geometry::Size {
79                    width: taffy::style::Dimension::from_length(400f32),
80                    height: taffy::style::Dimension::from_length(300f32),
81                },
82                ..Default::default()
83            },
84            &[node0],
85        )
86        .unwrap();
87    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
88    println!("\nComputed tree:");
89    taffy.print_tree(node);
90    println!();
91    let layout = taffy.layout(node).unwrap();
92    let Layout { size, location, .. } = layout;
93    assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node, 400f32, size.width);
94    assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node, 300f32, size.height);
95    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
96    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
97    let layout = taffy.layout(node0).unwrap();
98    let Layout { size, location, .. } = layout;
99    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
100    assert_eq!(size.height, 17f32, "height of node {:?}. Expected {}. Actual {}", node0, 17f32, size.height);
101    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
102    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
103}