gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1117HTML 1040Markdown 12TOML 94791 Definiciones

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/block_absolute_child_with_margin_x.rs Rust · 91 líneas · 4.4 KB Historia Quién tocó qué crudo

Implement CSS Block layout (`Display::Block`) (#474) 544399619 · Nico Burns ·

1#[test]
2fn block_absolute_child_with_margin_x() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout};
5    let mut taffy = taffy::Taffy::new();
6    let node0 = taffy
7        .new_leaf(taffy::style::Style {
8            position: taffy::style::Position::Absolute,
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::Length(9f32),
11                height: taffy::style::Dimension::Length(9f32),
12            },
13            margin: taffy::geometry::Rect {
14                left: taffy::style::LengthPercentageAuto::Length(7f32),
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            position: taffy::style::Position::Absolute,
25            size: taffy::geometry::Size {
26                width: taffy::style::Dimension::Length(9f32),
27                height: taffy::style::Dimension::Length(9f32),
28            },
29            margin: taffy::geometry::Rect {
30                left: zero(),
31                right: taffy::style::LengthPercentageAuto::Length(7f32),
32                top: zero(),
33                bottom: zero(),
34            },
35            ..Default::default()
36        })
37        .unwrap();
38    let node2 = taffy
39        .new_leaf(taffy::style::Style {
40            position: taffy::style::Position::Absolute,
41            size: taffy::geometry::Size {
42                width: taffy::style::Dimension::Length(9f32),
43                height: taffy::style::Dimension::Length(9f32),
44            },
45            margin: taffy::geometry::Rect {
46                left: taffy::style::LengthPercentageAuto::Length(10f32),
47                right: taffy::style::LengthPercentageAuto::Length(5f32),
48                top: zero(),
49                bottom: zero(),
50            },
51            ..Default::default()
52        })
53        .unwrap();
54    let node = taffy
55        .new_with_children(
56            taffy::style::Style {
57                display: taffy::style::Display::Block,
58                size: taffy::geometry::Size {
59                    width: taffy::style::Dimension::Length(20f32),
60                    height: taffy::style::Dimension::Length(37f32),
61                },
62                ..Default::default()
63            },
64            &[node0, node1, node2],
65        )
66        .unwrap();
67    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
68    println!("\nComputed tree:");
69    taffy::util::print_tree(&taffy, node);
70    println!();
71    let Layout { size, location, .. } = taffy.layout(node).unwrap();
72    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node, 20f32, size.width);
73    assert_eq!(size.height, 37f32, "height of node {:?}. Expected {}. Actual {}", node, 37f32, size.height);
74    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
75    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
76    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
77    assert_eq!(size.width, 9f32, "width of node {:?}. Expected {}. Actual {}", node0, 9f32, size.width);
78    assert_eq!(size.height, 9f32, "height of node {:?}. Expected {}. Actual {}", node0, 9f32, size.height);
79    assert_eq!(location.x, 7f32, "x of node {:?}. Expected {}. Actual {}", node0, 7f32, location.x);
80    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
81    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
82    assert_eq!(size.width, 9f32, "width of node {:?}. Expected {}. Actual {}", node1, 9f32, size.width);
83    assert_eq!(size.height, 9f32, "height of node {:?}. Expected {}. Actual {}", node1, 9f32, size.height);
84    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
85    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
86    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
87    assert_eq!(size.width, 9f32, "width of node {:?}. Expected {}. Actual {}", node2, 9f32, size.width);
88    assert_eq!(size.height, 9f32, "height of node {:?}. Expected {}. Actual {}", node2, 9f32, size.height);
89    assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node2, 10f32, location.x);
90    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
91}