tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Definitions

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