tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 10TOML 3CSS 1348 Sutichaykuna

⎇ 3bc35ec3b541eea8ea62344722f155ce9b22e227 tests/generated/flex/flex_basis_unconstraint_column.rs Rust · 150 siq'ikuna · 6.0 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

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