tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 229Rust 8TOML 3CSS 1310 Definiciones

⎇ float-layout tests/generated/flex/absolute_aspect_ratio_fill_height_from_inset.rs Rust · 101 líneas · 4.7 KB Historia Quién tocó qué crudo

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

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