gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 500HTML 254C 19JavaScript 81398 Definitions

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