tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1114HTML 1040Markdown 12TOML 94698 Definiciones

⎇ float-layout tests/generated/blockflex/blockflex_overflow_hidden.rs Rust · 170 líneas · 7.5 KB Historia Quién tocó qué crudo

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

1#[test]
2#[allow(non_snake_case)]
3fn blockflex_overflow_hidden__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                display: taffy::style::Display::Block,
11                overflow: taffy::geometry::Point {
12                    x: taffy::style::Overflow::Hidden,
13                    y: taffy::style::Overflow::Hidden,
14                },
15                scrollbar_width: 15f32,
16                flex_grow: 1f32,
17                ..Default::default()
18            },
19            crate::TestNodeContext::ahem_text("HHHH\u{200b}HH", crate::WritingMode::Horizontal),
20        )
21        .unwrap();
22    let node1 = taffy
23        .new_leaf_with_context(
24            taffy::style::Style { display: taffy::style::Display::Block, flex_grow: 1f32, ..Default::default() },
25            crate::TestNodeContext::ahem_text("HHHH\u{200b}HH", crate::WritingMode::Horizontal),
26        )
27        .unwrap();
28    let node = taffy
29        .new_with_children(
30            taffy::style::Style {
31                display: taffy::style::Display::Flex,
32                size: taffy::geometry::Size {
33                    width: taffy::style::Dimension::from_length(20f32),
34                    height: taffy::style::Dimension::from_length(50f32),
35                },
36                ..Default::default()
37            },
38            &[node0, node1],
39        )
40        .unwrap();
41    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
42    println!("\nComputed tree:");
43    taffy.print_tree(node);
44    println!();
45    let layout = taffy.layout(node).unwrap();
46    let Layout { size, location, .. } = layout;
47    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node, 20f32, size.width);
48    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
49    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
50    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
51    let layout = taffy.layout(node0).unwrap();
52    let Layout { size, location, .. } = layout;
53    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node0, 0f32, size.width);
54    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
55    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
56    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
57    #[cfg(feature = "content_size")]
58    assert_eq!(
59        layout.scroll_width(),
60        40f32,
61        "scroll_width of node {:?}. Expected {}. Actual {}",
62        node0,
63        40f32,
64        layout.scroll_width()
65    );
66    #[cfg(feature = "content_size")]
67    assert_eq!(
68        layout.scroll_height(),
69        0f32,
70        "scroll_height of node {:?}. Expected {}. Actual {}",
71        node0,
72        0f32,
73        layout.scroll_height()
74    );
75    let layout = taffy.layout(node1).unwrap();
76    let Layout { size, location, .. } = layout;
77    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
78    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
79    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
80    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
81}
82
83#[test]
84#[allow(non_snake_case)]
85fn blockflex_overflow_hidden__content_box() {
86    #[allow(unused_imports)]
87    use taffy::{prelude::*, Layout};
88    let mut taffy = crate::new_test_tree();
89    let node0 = taffy
90        .new_leaf_with_context(
91            taffy::style::Style {
92                display: taffy::style::Display::Block,
93                box_sizing: taffy::style::BoxSizing::ContentBox,
94                overflow: taffy::geometry::Point {
95                    x: taffy::style::Overflow::Hidden,
96                    y: taffy::style::Overflow::Hidden,
97                },
98                scrollbar_width: 15f32,
99                flex_grow: 1f32,
100                ..Default::default()
101            },
102            crate::TestNodeContext::ahem_text("HHHH\u{200b}HH", crate::WritingMode::Horizontal),
103        )
104        .unwrap();
105    let node1 = taffy
106        .new_leaf_with_context(
107            taffy::style::Style {
108                display: taffy::style::Display::Block,
109                box_sizing: taffy::style::BoxSizing::ContentBox,
110                flex_grow: 1f32,
111                ..Default::default()
112            },
113            crate::TestNodeContext::ahem_text("HHHH\u{200b}HH", crate::WritingMode::Horizontal),
114        )
115        .unwrap();
116    let node = taffy
117        .new_with_children(
118            taffy::style::Style {
119                display: taffy::style::Display::Flex,
120                box_sizing: taffy::style::BoxSizing::ContentBox,
121                size: taffy::geometry::Size {
122                    width: taffy::style::Dimension::from_length(20f32),
123                    height: taffy::style::Dimension::from_length(50f32),
124                },
125                ..Default::default()
126            },
127            &[node0, node1],
128        )
129        .unwrap();
130    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
131    println!("\nComputed tree:");
132    taffy.print_tree(node);
133    println!();
134    let layout = taffy.layout(node).unwrap();
135    let Layout { size, location, .. } = layout;
136    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node, 20f32, size.width);
137    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
138    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
139    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
140    let layout = taffy.layout(node0).unwrap();
141    let Layout { size, location, .. } = layout;
142    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node0, 0f32, size.width);
143    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
144    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
145    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
146    #[cfg(feature = "content_size")]
147    assert_eq!(
148        layout.scroll_width(),
149        40f32,
150        "scroll_width of node {:?}. Expected {}. Actual {}",
151        node0,
152        40f32,
153        layout.scroll_width()
154    );
155    #[cfg(feature = "content_size")]
156    assert_eq!(
157        layout.scroll_height(),
158        0f32,
159        "scroll_height of node {:?}. Expected {}. Actual {}",
160        node0,
161        0f32,
162        layout.scroll_height()
163    );
164    let layout = taffy.layout(node1).unwrap();
165    let Layout { size, location, .. } = layout;
166    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1, 40f32, size.width);
167    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
168    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
169    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
170}