gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 8TOML 3CSS 1317 Sutichaykuna

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/block_padding_border_fixed_size.rs Rust · 62 siq'ikuna · 3.3 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

1#[test]
2fn block_padding_border_fixed_size() {
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            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
9            ..Default::default()
10        })
11        .unwrap();
12    let node1 = taffy
13        .new_leaf(taffy::style::Style {
14            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
15            ..Default::default()
16        })
17        .unwrap();
18    let node = taffy
19        .new_with_children(
20            taffy::style::Style {
21                display: taffy::style::Display::Block,
22                size: taffy::geometry::Size {
23                    width: taffy::style::Dimension::Length(50f32),
24                    height: taffy::style::Dimension::Length(50f32),
25                },
26                padding: taffy::geometry::Rect {
27                    left: taffy::style::LengthPercentage::Length(7f32),
28                    right: taffy::style::LengthPercentage::Length(3f32),
29                    top: taffy::style::LengthPercentage::Length(1f32),
30                    bottom: taffy::style::LengthPercentage::Length(5f32),
31                },
32                border: taffy::geometry::Rect {
33                    left: taffy::style::LengthPercentage::Length(8f32),
34                    right: taffy::style::LengthPercentage::Length(4f32),
35                    top: taffy::style::LengthPercentage::Length(2f32),
36                    bottom: taffy::style::LengthPercentage::Length(6f32),
37                },
38                ..Default::default()
39            },
40            &[node0, node1],
41        )
42        .unwrap();
43    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
44    println!("\nComputed tree:");
45    taffy::util::print_tree(&taffy, node);
46    println!();
47    let Layout { size, location, .. } = taffy.layout(node).unwrap();
48    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
49    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
50    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
51    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
52    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
53    assert_eq!(size.width, 28f32, "width of node {:?}. Expected {}. Actual {}", node0, 28f32, size.width);
54    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
55    assert_eq!(location.x, 15f32, "x of node {:?}. Expected {}. Actual {}", node0, 15f32, location.x);
56    assert_eq!(location.y, 3f32, "y of node {:?}. Expected {}. Actual {}", node0, 3f32, location.y);
57    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
58    assert_eq!(size.width, 28f32, "width of node {:?}. Expected {}. Actual {}", node1, 28f32, size.width);
59    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
60    assert_eq!(location.x, 15f32, "x of node {:?}. Expected {}. Actual {}", node1, 15f32, location.x);
61    assert_eq!(location.y, 13f32, "y of node {:?}. Expected {}. Actual {}", node1, 13f32, location.y);
62}