tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

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