gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definiciones

⎇ 04e20d1de5cd584bf0760071cf130dd55f5b0089 tests/generated/flex/aspect_ratio_flex_row_fill_max_width.rs Rust · 86 líneas · 3.4 KB Historia Quién tocó qué crudo

Rename Taffy struct to TaffyTree (#580) 17235ffa2 · Nico Burns ·

1#[test]
2fn aspect_ratio_flex_row_fill_max_width() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6    let node0 = taffy
7        .new_leaf_with_context(
8            taffy::style::Style {
9                max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(20f32) },
10                aspect_ratio: Some(2f32),
11                ..Default::default()
12            },
13            crate::TextMeasure {
14                text_content: "HH\u{200b}HH\u{200b}HH\u{200b}HH",
15                writing_mode: crate::WritingMode::Horizontal,
16                _aspect_ratio: Some(2f32),
17            },
18        )
19        .unwrap();
20    let node = taffy
21        .new_with_children(
22            taffy::style::Style {
23                display: taffy::style::Display::Flex,
24                align_items: Some(taffy::style::AlignItems::Start),
25                size: taffy::geometry::Size {
26                    width: taffy::style::Dimension::Length(100f32),
27                    height: taffy::style::Dimension::Length(100f32),
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    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
39    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
40    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
41    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, 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    #[cfg(feature = "content_size")]
45    assert_eq!(
46        layout.scroll_width(),
47        0f32,
48        "scroll_width of node {:?}. Expected {}. Actual {}",
49        node,
50        0f32,
51        layout.scroll_width()
52    );
53    #[cfg(feature = "content_size")]
54    assert_eq!(
55        layout.scroll_height(),
56        0f32,
57        "scroll_height of node {:?}. Expected {}. Actual {}",
58        node,
59        0f32,
60        layout.scroll_height()
61    );
62    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
63    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
64    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
65    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
66    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
67    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
68    #[cfg(feature = "content_size")]
69    assert_eq!(
70        layout.scroll_width(),
71        0f32,
72        "scroll_width of node {:?}. Expected {}. Actual {}",
73        node0,
74        0f32,
75        layout.scroll_width()
76    );
77    #[cfg(feature = "content_size")]
78    assert_eq!(
79        layout.scroll_height(),
80        0f32,
81        "scroll_height of node {:?}. Expected {}. Actual {}",
82        node0,
83        0f32,
84        layout.scroll_height()
85    );
86}