tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Definiciones

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