tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Definitions

⎇ 9f1d71c97e0852760580b7d7bb30f503baa6a988 tests/generated/flex/taffy_issue_696_overflow_hidden.rs Rust · 180 lines · 8.3 KB History Who touched what raw

Fix intrinsic size of scroll containers that have a small explicit flex-basis (#728) 9f1d71c97 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn taffy_issue_696_overflow_hidden__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, tree::Layout, TaffyTree};
6    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
7    let node00 = taffy
8        .new_leaf(taffy::style::Style {
9            display: taffy::style::Display::Flex,
10            flex_shrink: 0f32,
11            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(200f32) },
12            ..Default::default()
13        })
14        .unwrap();
15    let node0 = taffy
16        .new_with_children(
17            taffy::style::Style {
18                display: taffy::style::Display::Flex,
19                flex_direction: taffy::style::FlexDirection::Column,
20                overflow: taffy::geometry::Point {
21                    x: taffy::style::Overflow::Hidden,
22                    y: taffy::style::Overflow::Hidden,
23                },
24                scrollbar_width: 15f32,
25                flex_basis: taffy::style::Dimension::Length(0f32),
26                padding: taffy::geometry::Rect {
27                    left: taffy::style::LengthPercentage::Length(20f32),
28                    right: taffy::style::LengthPercentage::Length(20f32),
29                    top: taffy::style::LengthPercentage::Length(20f32),
30                    bottom: taffy::style::LengthPercentage::Length(20f32),
31                },
32                ..Default::default()
33            },
34            &[node00],
35        )
36        .unwrap();
37    let node = taffy
38        .new_with_children(
39            taffy::style::Style {
40                display: taffy::style::Display::Flex,
41                flex_direction: taffy::style::FlexDirection::Column,
42                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(200f32), height: auto() },
43                ..Default::default()
44            },
45            &[node0],
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    let layout = taffy.layout(node).unwrap();
53    let Layout { size, location, .. } = layout;
54    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
55    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, 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    let layout = taffy.layout(node0).unwrap();
59    let Layout { size, location, .. } = layout;
60    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
61    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
62    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
63    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
64    #[cfg(feature = "content_size")]
65    assert_eq!(
66        layout.scroll_width(),
67        0f32,
68        "scroll_width of node {:?}. Expected {}. Actual {}",
69        node0,
70        0f32,
71        layout.scroll_width()
72    );
73    #[cfg(feature = "content_size")]
74    assert_eq!(
75        layout.scroll_height(),
76        200f32,
77        "scroll_height of node {:?}. Expected {}. Actual {}",
78        node0,
79        200f32,
80        layout.scroll_height()
81    );
82    let layout = taffy.layout(node00).unwrap();
83    let Layout { size, location, .. } = layout;
84    assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node00, 160f32, size.width);
85    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node00, 200f32, size.height);
86    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node00, 20f32, location.x);
87    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node00, 20f32, location.y);
88}
89
90#[test]
91#[allow(non_snake_case)]
92fn taffy_issue_696_overflow_hidden__content_box() {
93    #[allow(unused_imports)]
94    use taffy::{prelude::*, tree::Layout, TaffyTree};
95    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
96    let node00 = taffy
97        .new_leaf(taffy::style::Style {
98            display: taffy::style::Display::Flex,
99            box_sizing: taffy::style::BoxSizing::ContentBox,
100            flex_shrink: 0f32,
101            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(200f32) },
102            ..Default::default()
103        })
104        .unwrap();
105    let node0 = taffy
106        .new_with_children(
107            taffy::style::Style {
108                display: taffy::style::Display::Flex,
109                box_sizing: taffy::style::BoxSizing::ContentBox,
110                flex_direction: taffy::style::FlexDirection::Column,
111                overflow: taffy::geometry::Point {
112                    x: taffy::style::Overflow::Hidden,
113                    y: taffy::style::Overflow::Hidden,
114                },
115                scrollbar_width: 15f32,
116                flex_basis: taffy::style::Dimension::Length(0f32),
117                padding: taffy::geometry::Rect {
118                    left: taffy::style::LengthPercentage::Length(20f32),
119                    right: taffy::style::LengthPercentage::Length(20f32),
120                    top: taffy::style::LengthPercentage::Length(20f32),
121                    bottom: taffy::style::LengthPercentage::Length(20f32),
122                },
123                ..Default::default()
124            },
125            &[node00],
126        )
127        .unwrap();
128    let node = taffy
129        .new_with_children(
130            taffy::style::Style {
131                display: taffy::style::Display::Flex,
132                box_sizing: taffy::style::BoxSizing::ContentBox,
133                flex_direction: taffy::style::FlexDirection::Column,
134                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(200f32), height: auto() },
135                ..Default::default()
136            },
137            &[node0],
138        )
139        .unwrap();
140    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
141    println!("\nComputed tree:");
142    taffy.print_tree(node);
143    println!();
144    let layout = taffy.layout(node).unwrap();
145    let Layout { size, location, .. } = layout;
146    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
147    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, size.height);
148    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
149    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
150    let layout = taffy.layout(node0).unwrap();
151    let Layout { size, location, .. } = layout;
152    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
153    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
154    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
155    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
156    #[cfg(feature = "content_size")]
157    assert_eq!(
158        layout.scroll_width(),
159        0f32,
160        "scroll_width of node {:?}. Expected {}. Actual {}",
161        node0,
162        0f32,
163        layout.scroll_width()
164    );
165    #[cfg(feature = "content_size")]
166    assert_eq!(
167        layout.scroll_height(),
168        200f32,
169        "scroll_height of node {:?}. Expected {}. Actual {}",
170        node0,
171        200f32,
172        layout.scroll_height()
173    );
174    let layout = taffy.layout(node00).unwrap();
175    let Layout { size, location, .. } = layout;
176    assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node00, 160f32, size.width);
177    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node00, 200f32, size.height);
178    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node00, 20f32, location.x);
179    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node00, 20f32, location.y);
180}