tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 788HTML 740Markdown 12TOML 62536 Definiciones

⎇ float-layout tests/generated/block/block_margin_y_collapse_through_positive.rs Rust · 141 líneas · 7.9 KB Historia Quién tocó qué crudo

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn block_margin_y_collapse_through_positive__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node0 = taffy
8        .new_leaf(taffy::style::Style {
9            display: taffy::style::Display::Block,
10            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
11            margin: taffy::geometry::Rect { left: zero(), right: zero(), top: zero(), bottom: length(10f32) },
12            ..Default::default()
13        })
14        .unwrap();
15    let node1 = taffy
16        .new_leaf(taffy::style::Style {
17            display: taffy::style::Display::Block,
18            margin: taffy::geometry::Rect { left: zero(), right: zero(), top: length(10f32), bottom: length(10f32) },
19            ..Default::default()
20        })
21        .unwrap();
22    let node2 = taffy
23        .new_leaf(taffy::style::Style {
24            display: taffy::style::Display::Block,
25            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
26            margin: taffy::geometry::Rect { left: zero(), right: zero(), top: length(10f32), bottom: zero() },
27            ..Default::default()
28        })
29        .unwrap();
30    let node = taffy
31        .new_with_children(
32            taffy::style::Style {
33                display: taffy::style::Display::Block,
34                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
35                ..Default::default()
36            },
37            &[node0, node1, node2],
38        )
39        .unwrap();
40    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
41    println!("\nComputed tree:");
42    taffy.print_tree(node);
43    println!();
44    let layout = taffy.layout(node).unwrap();
45    let Layout { size, location, .. } = layout;
46    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
47    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, size.height);
48    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
49    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
50    let layout = taffy.layout(node0).unwrap();
51    let Layout { size, location, .. } = layout;
52    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
53    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
54    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
55    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
56    let layout = taffy.layout(node1).unwrap();
57    let Layout { size, location, .. } = layout;
58    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
59    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node1, 0f32, size.height);
60    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
61    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node1, 20f32, location.y);
62    let layout = taffy.layout(node2).unwrap();
63    let Layout { size, location, .. } = layout;
64    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
65    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
66    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
67    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node2, 20f32, location.y);
68}
69
70#[test]
71#[allow(non_snake_case)]
72fn block_margin_y_collapse_through_positive__content_box() {
73    #[allow(unused_imports)]
74    use taffy::{prelude::*, Layout};
75    let mut taffy = crate::new_test_tree();
76    let node0 = taffy
77        .new_leaf(taffy::style::Style {
78            display: taffy::style::Display::Block,
79            box_sizing: taffy::style::BoxSizing::ContentBox,
80            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
81            margin: taffy::geometry::Rect { left: zero(), right: zero(), top: zero(), bottom: length(10f32) },
82            ..Default::default()
83        })
84        .unwrap();
85    let node1 = taffy
86        .new_leaf(taffy::style::Style {
87            display: taffy::style::Display::Block,
88            box_sizing: taffy::style::BoxSizing::ContentBox,
89            margin: taffy::geometry::Rect { left: zero(), right: zero(), top: length(10f32), bottom: length(10f32) },
90            ..Default::default()
91        })
92        .unwrap();
93    let node2 = taffy
94        .new_leaf(taffy::style::Style {
95            display: taffy::style::Display::Block,
96            box_sizing: taffy::style::BoxSizing::ContentBox,
97            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(10f32) },
98            margin: taffy::geometry::Rect { left: zero(), right: zero(), top: length(10f32), bottom: zero() },
99            ..Default::default()
100        })
101        .unwrap();
102    let node = taffy
103        .new_with_children(
104            taffy::style::Style {
105                display: taffy::style::Display::Block,
106                box_sizing: taffy::style::BoxSizing::ContentBox,
107                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
108                ..Default::default()
109            },
110            &[node0, node1, node2],
111        )
112        .unwrap();
113    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
114    println!("\nComputed tree:");
115    taffy.print_tree(node);
116    println!();
117    let layout = taffy.layout(node).unwrap();
118    let Layout { size, location, .. } = layout;
119    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
120    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node, 30f32, size.height);
121    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
122    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
123    let layout = taffy.layout(node0).unwrap();
124    let Layout { size, location, .. } = layout;
125    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
126    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
127    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
128    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
129    let layout = taffy.layout(node1).unwrap();
130    let Layout { size, location, .. } = layout;
131    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
132    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node1, 0f32, size.height);
133    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
134    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node1, 20f32, location.y);
135    let layout = taffy.layout(node2).unwrap();
136    let Layout { size, location, .. } = layout;
137    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
138    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node2, 10f32, size.height);
139    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
140    assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node2, 20f32, location.y);
141}