gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1086HTML 1018Markdown 12TOML 84406 Sutichaykuna

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/block_absolute_margin_auto_left_with_inset.rs Rust · 55 siq'ikuna · 2.6 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_left_with_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: taffy::style::LengthPercentageAuto::Auto,
15                right: zero(),
16                top: zero(),
17                bottom: zero(),
18            },
19            inset: taffy::geometry::Rect {
20                left: taffy::style::LengthPercentageAuto::Length(10f32),
21                right: taffy::style::LengthPercentageAuto::Length(20f32),
22                top: auto(),
23                bottom: auto(),
24            },
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 {
33                    width: taffy::style::Dimension::Length(200f32),
34                    height: taffy::style::Dimension::Length(200f32),
35                },
36                ..Default::default()
37            },
38            &[node0],
39        )
40        .unwrap();
41    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
42    println!("\nComputed tree:");
43    taffy::util::print_tree(&taffy, node);
44    println!();
45    let Layout { size, location, .. } = taffy.layout(node).unwrap();
46    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
47    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
48    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
49    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
50    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
51    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
52    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
53    assert_eq!(location.x, 130f32, "x of node {:?}. Expected {}. Actual {}", node0, 130f32, location.x);
54    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
55}