tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 976HTML 921Markdown 12TOML 82979 Definitions

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