gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 9TOML 3CSS 1344 Definitions

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/block_margin_y_last_child_collapse_negative_equal.rs Rust · 76 lines · 3.8 KB History Who touched what raw

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

1#[test]
2fn block_margin_y_last_child_collapse_negative_equal() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout};
5    let mut taffy = taffy::Taffy::new();
6    let node000 = taffy
7        .new_leaf(taffy::style::Style {
8            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
9            ..Default::default()
10        })
11        .unwrap();
12    let node00 = taffy
13        .new_with_children(
14            taffy::style::Style {
15                display: taffy::style::Display::Block,
16                margin: taffy::geometry::Rect {
17                    left: zero(),
18                    right: zero(),
19                    top: zero(),
20                    bottom: taffy::style::LengthPercentageAuto::Length(-10f32),
21                },
22                ..Default::default()
23            },
24            &[node000],
25        )
26        .unwrap();
27    let node0 = taffy
28        .new_with_children(
29            taffy::style::Style {
30                display: taffy::style::Display::Block,
31                margin: taffy::geometry::Rect {
32                    left: zero(),
33                    right: zero(),
34                    top: zero(),
35                    bottom: taffy::style::LengthPercentageAuto::Length(-10f32),
36                },
37                ..Default::default()
38            },
39            &[node00],
40        )
41        .unwrap();
42    let node = taffy
43        .new_with_children(
44            taffy::style::Style {
45                display: taffy::style::Display::Block,
46                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
47                ..Default::default()
48            },
49            &[node0],
50        )
51        .unwrap();
52    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
53    println!("\nComputed tree:");
54    taffy::util::print_tree(&taffy, node);
55    println!();
56    let Layout { size, location, .. } = taffy.layout(node).unwrap();
57    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
58    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node, 0f32, size.height);
59    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
60    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
61    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
62    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
63    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
64    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
65    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
66    let Layout { size, location, .. } = taffy.layout(node00).unwrap();
67    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node00, 50f32, size.width);
68    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00, 10f32, size.height);
69    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
70    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
71    let Layout { size, location, .. } = taffy.layout(node000).unwrap();
72    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node000, 50f32, size.width);
73    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node000, 10f32, size.height);
74    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000, 0f32, location.x);
75    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node000, 0f32, location.y);
76}