gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1090HTML 1022Markdown 12TOML 84418 Sutichaykuna

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/block_absolute_margin_auto_top_without_inset.rs Rust · 50 siq'ikuna · 2.4 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

1#[test]
2fn block_absolute_margin_auto_top_without_inset() {
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(50f32),
11                height: taffy::style::Dimension::Length(50f32),
12            },
13            margin: taffy::geometry::Rect {
14                left: zero(),
15                right: zero(),
16                top: taffy::style::LengthPercentageAuto::Auto,
17                bottom: zero(),
18            },
19            ..Default::default()
20        })
21        .unwrap();
22    let node = taffy
23        .new_with_children(
24            taffy::style::Style {
25                display: taffy::style::Display::Block,
26                align_items: Some(taffy::style::AlignItems::Center),
27                size: taffy::geometry::Size {
28                    width: taffy::style::Dimension::Length(200f32),
29                    height: taffy::style::Dimension::Length(200f32),
30                },
31                ..Default::default()
32            },
33            &[node0],
34        )
35        .unwrap();
36    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
37    println!("\nComputed tree:");
38    taffy::util::print_tree(&taffy, node);
39    println!();
40    let Layout { size, location, .. } = taffy.layout(node).unwrap();
41    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
42    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
43    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
44    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
45    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
46    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
47    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
48    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
49    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
50}