tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 229Rust 8TOML 3CSS 1310 Definitions

⎇ float-layout tests/generated/block/block_align_baseline_child_top2.rs Rust · 169 lines · 8.5 KB History Who touched what raw

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

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