gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 252HTML 238TOML 3CSS 1626 Definiciones

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