tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 10TOML 3CSS 1348 Definiciones

⎇ 3bc35ec3b541eea8ea62344722f155ce9b22e227 tests/generated/flex/padding_flex_child.rs Rust · 171 líneas · 6.9 KB Historia Quién tocó qué crudo

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

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