tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Definitions

⎇ 9f1d71c97e0852760580b7d7bb30f503baa6a988 tests/generated/flex/taffy_issue_696_min_height.rs Rust · 136 lines · 7.2 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_min_height__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                flex_basis: taffy::style::Dimension::Length(0f32),
21                min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(100f32) },
22                padding: taffy::geometry::Rect {
23                    left: taffy::style::LengthPercentage::Length(20f32),
24                    right: taffy::style::LengthPercentage::Length(20f32),
25                    top: taffy::style::LengthPercentage::Length(20f32),
26                    bottom: taffy::style::LengthPercentage::Length(20f32),
27                },
28                ..Default::default()
29            },
30            &[node00],
31        )
32        .unwrap();
33    let node = taffy
34        .new_with_children(
35            taffy::style::Style {
36                display: taffy::style::Display::Flex,
37                flex_direction: taffy::style::FlexDirection::Column,
38                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(200f32), height: auto() },
39                ..Default::default()
40            },
41            &[node0],
42        )
43        .unwrap();
44    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
45    println!("\nComputed tree:");
46    taffy.print_tree(node);
47    println!();
48    let layout = taffy.layout(node).unwrap();
49    let Layout { size, location, .. } = layout;
50    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
51    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
52    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
53    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
54    let layout = taffy.layout(node0).unwrap();
55    let Layout { size, location, .. } = layout;
56    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
57    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
58    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
59    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
60    let layout = taffy.layout(node00).unwrap();
61    let Layout { size, location, .. } = layout;
62    assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node00, 160f32, size.width);
63    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node00, 200f32, size.height);
64    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node00, 20f32, location.x);
65    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node00, 20f32, location.y);
66}
67
68#[test]
69#[allow(non_snake_case)]
70fn taffy_issue_696_min_height__content_box() {
71    #[allow(unused_imports)]
72    use taffy::{prelude::*, tree::Layout, TaffyTree};
73    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
74    let node00 = taffy
75        .new_leaf(taffy::style::Style {
76            display: taffy::style::Display::Flex,
77            box_sizing: taffy::style::BoxSizing::ContentBox,
78            flex_shrink: 0f32,
79            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(200f32) },
80            ..Default::default()
81        })
82        .unwrap();
83    let node0 = taffy
84        .new_with_children(
85            taffy::style::Style {
86                display: taffy::style::Display::Flex,
87                box_sizing: taffy::style::BoxSizing::ContentBox,
88                flex_direction: taffy::style::FlexDirection::Column,
89                flex_basis: taffy::style::Dimension::Length(0f32),
90                min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(100f32) },
91                padding: taffy::geometry::Rect {
92                    left: taffy::style::LengthPercentage::Length(20f32),
93                    right: taffy::style::LengthPercentage::Length(20f32),
94                    top: taffy::style::LengthPercentage::Length(20f32),
95                    bottom: taffy::style::LengthPercentage::Length(20f32),
96                },
97                ..Default::default()
98            },
99            &[node00],
100        )
101        .unwrap();
102    let node = taffy
103        .new_with_children(
104            taffy::style::Style {
105                display: taffy::style::Display::Flex,
106                box_sizing: taffy::style::BoxSizing::ContentBox,
107                flex_direction: taffy::style::FlexDirection::Column,
108                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(200f32), height: auto() },
109                ..Default::default()
110            },
111            &[node0],
112        )
113        .unwrap();
114    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
115    println!("\nComputed tree:");
116    taffy.print_tree(node);
117    println!();
118    let layout = taffy.layout(node).unwrap();
119    let Layout { size, location, .. } = layout;
120    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
121    assert_eq!(size.height, 140f32, "height of node {:?}. Expected {}. Actual {}", node, 140f32, size.height);
122    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
123    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
124    let layout = taffy.layout(node0).unwrap();
125    let Layout { size, location, .. } = layout;
126    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
127    assert_eq!(size.height, 140f32, "height of node {:?}. Expected {}. Actual {}", node0, 140f32, size.height);
128    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
129    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
130    let layout = taffy.layout(node00).unwrap();
131    let Layout { size, location, .. } = layout;
132    assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node00, 160f32, size.width);
133    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node00, 200f32, size.height);
134    assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node00, 20f32, location.x);
135    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node00, 20f32, location.y);
136}