gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 227Rust 7TOML 3CSS 1307 Definiciones

⎇ 0.5.x tests/generated/blockflex/blockflex_overflow_hidden.rs Rust · 124 líneas · 4.9 KB Historia Quién tocó qué crudo

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

1#[test]
2fn blockflex_overflow_hidden() {
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                display: taffy::style::Display::Block,
10                overflow: taffy::geometry::Point {
11                    x: taffy::style::Overflow::Hidden,
12                    y: taffy::style::Overflow::Hidden,
13                },
14                scrollbar_width: 15f32,
15                flex_grow: 1f32,
16                ..Default::default()
17            },
18            crate::TextMeasure {
19                text_content: "HHHH\u{200b}HH",
20                writing_mode: crate::WritingMode::Horizontal,
21                _aspect_ratio: None,
22            },
23        )
24        .unwrap();
25    let node1 = taffy
26        .new_leaf_with_context(
27            taffy::style::Style { display: taffy::style::Display::Block, flex_grow: 1f32, ..Default::default() },
28            crate::TextMeasure {
29                text_content: "HHHH\u{200b}HH",
30                writing_mode: crate::WritingMode::Horizontal,
31                _aspect_ratio: None,
32            },
33        )
34        .unwrap();
35    let node = taffy
36        .new_with_children(
37            taffy::style::Style {
38                display: taffy::style::Display::Flex,
39                size: taffy::geometry::Size {
40                    width: taffy::style::Dimension::Length(20f32),
41                    height: taffy::style::Dimension::Length(50f32),
42                },
43                ..Default::default()
44            },
45            &[node0, node1],
46        )
47        .unwrap();
48    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
49    println!("\nComputed tree:");
50    taffy.print_tree(node);
51    println!();
52    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
53    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
54    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node, 20f32, size.width);
55    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
56    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
57    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
58    #[cfg(feature = "content_size")]
59    assert_eq!(
60        layout.scroll_width(),
61        20f32,
62        "scroll_width of node {:?}. Expected {}. Actual {}",
63        node,
64        20f32,
65        layout.scroll_width()
66    );
67    #[cfg(feature = "content_size")]
68    assert_eq!(
69        layout.scroll_height(),
70        0f32,
71        "scroll_height of node {:?}. Expected {}. Actual {}",
72        node,
73        0f32,
74        layout.scroll_height()
75    );
76    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
77    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
78    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node0, 0f32, size.width);
79    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
80    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
81    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
82    #[cfg(feature = "content_size")]
83    assert_eq!(
84        layout.scroll_width(),
85        40f32,
86        "scroll_width of node {:?}. Expected {}. Actual {}",
87        node0,
88        40f32,
89        layout.scroll_width()
90    );
91    #[cfg(feature = "content_size")]
92    assert_eq!(
93        layout.scroll_height(),
94        0f32,
95        "scroll_height of node {:?}. Expected {}. Actual {}",
96        node0,
97        0f32,
98        layout.scroll_height()
99    );
100    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
101    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
102    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
103    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
104    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
105    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
106    #[cfg(feature = "content_size")]
107    assert_eq!(
108        layout.scroll_width(),
109        0f32,
110        "scroll_width of node {:?}. Expected {}. Actual {}",
111        node1,
112        0f32,
113        layout.scroll_width()
114    );
115    #[cfg(feature = "content_size")]
116    assert_eq!(
117        layout.scroll_height(),
118        0f32,
119        "scroll_height of node {:?}. Expected {}. Actual {}",
120        node1,
121        0f32,
122        layout.scroll_height()
123    );
124}