tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1082HTML 1014Markdown 12TOML 83222 Definitions

⎇ float-layout tests/generated/grid/grid_aspect_ratio_fill_child_max_width.rs Rust · 95 lines · 4.7 KB History Who touched what raw

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

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