tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 10TOML 3CSS 1348 Definitions

⎇ 3bc35ec3b541eea8ea62344722f155ce9b22e227 tests/generated/flex/absolute_minmax_bottom_right_max.rs Rust · 185 lines · 7.3 KB History Who touched what raw

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

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