tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5364Rust 86Markdown 12TOML 91841 Definiciones

⎇ 9f1d71c97e0852760580b7d7bb30f503baa6a988 tests/generated/flex/taffy_issue_696.rs Rust · 182 líneas · 8.5 KB Historia Quién tocó qué crudo

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