gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1076HTML 1008Markdown 12TOML 83208 Definiciones

⎇ c154b8aa719da0d6f8636b123765a47fa40a3306 tests/generated/flex/nested_overflowing_child_in_constraint_parent.rs Rust · 115 líneas · 4.5 KB Historia Quién tocó qué crudo

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

1#[test]
2fn nested_overflowing_child_in_constraint_parent() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6    let node00 = taffy
7        .new_leaf(taffy::style::Style {
8            size: taffy::geometry::Size {
9                width: taffy::style::Dimension::Length(200f32),
10                height: taffy::style::Dimension::Length(200f32),
11            },
12            ..Default::default()
13        })
14        .unwrap();
15    let node0 = taffy
16        .new_with_children(
17            taffy::style::Style {
18                size: taffy::geometry::Size {
19                    width: taffy::style::Dimension::Length(100f32),
20                    height: taffy::style::Dimension::Length(100f32),
21                },
22                ..Default::default()
23            },
24            &[node00],
25        )
26        .unwrap();
27    let node = taffy
28        .new_with_children(
29            taffy::style::Style {
30                size: taffy::geometry::Size {
31                    width: taffy::style::Dimension::Length(100f32),
32                    height: taffy::style::Dimension::Length(100f32),
33                },
34                ..Default::default()
35            },
36            &[node0],
37        )
38        .unwrap();
39    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
40    println!("\nComputed tree:");
41    taffy.print_tree(node);
42    println!();
43    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
44    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
45    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
46    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
47    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
48    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
49    #[cfg(feature = "content_size")]
50    assert_eq!(
51        layout.scroll_width(),
52        0f32,
53        "scroll_width of node {:?}. Expected {}. Actual {}",
54        node,
55        0f32,
56        layout.scroll_width()
57    );
58    #[cfg(feature = "content_size")]
59    assert_eq!(
60        layout.scroll_height(),
61        100f32,
62        "scroll_height of node {:?}. Expected {}. Actual {}",
63        node,
64        100f32,
65        layout.scroll_height()
66    );
67    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
68    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
69    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
70    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
71    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
72    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
73    #[cfg(feature = "content_size")]
74    assert_eq!(
75        layout.scroll_width(),
76        0f32,
77        "scroll_width of node {:?}. Expected {}. Actual {}",
78        node0,
79        0f32,
80        layout.scroll_width()
81    );
82    #[cfg(feature = "content_size")]
83    assert_eq!(
84        layout.scroll_height(),
85        100f32,
86        "scroll_height of node {:?}. Expected {}. Actual {}",
87        node0,
88        100f32,
89        layout.scroll_height()
90    );
91    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
92    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
93    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node00, 100f32, size.width);
94    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node00, 200f32, size.height);
95    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
96    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
97    #[cfg(feature = "content_size")]
98    assert_eq!(
99        layout.scroll_width(),
100        0f32,
101        "scroll_width of node {:?}. Expected {}. Actual {}",
102        node00,
103        0f32,
104        layout.scroll_width()
105    );
106    #[cfg(feature = "content_size")]
107    assert_eq!(
108        layout.scroll_height(),
109        0f32,
110        "scroll_height of node {:?}. Expected {}. Actual {}",
111        node00,
112        0f32,
113        layout.scroll_height()
114    );
115}