gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 252HTML 238TOML 3CSS 1626 Definitions

⎇ 25571b5d07206880207e451af69dd3b49b113628 tests/generated/flex/aspect_ratio_flex_row_fill_max_width.rs Rust · 177 lines · 7.0 KB History Who touched what raw

Implement `box-sizing: content-box` (#675) a4976764b · Nico Burns ·

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