gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1090HTML 1022Markdown 12TOML 84418 Definitions

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