gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 683HTML 640Markdown 11TOML 62269 Sutichaykuna

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/block_align_baseline_child.rs Rust · 75 siq'ikuna · 3.8 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

1#[test]
2fn block_align_baseline_child() {
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            display: taffy::style::Display::Block,
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::Length(50f32),
11                height: taffy::style::Dimension::Length(50f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node10 = taffy
17        .new_leaf(taffy::style::Style {
18            size: taffy::geometry::Size {
19                width: taffy::style::Dimension::Length(50f32),
20                height: taffy::style::Dimension::Length(10f32),
21            },
22            ..Default::default()
23        })
24        .unwrap();
25    let node1 = taffy
26        .new_with_children(
27            taffy::style::Style {
28                display: taffy::style::Display::Block,
29                size: taffy::geometry::Size {
30                    width: taffy::style::Dimension::Length(50f32),
31                    height: taffy::style::Dimension::Length(20f32),
32                },
33                ..Default::default()
34            },
35            &[node10],
36        )
37        .unwrap();
38    let node = taffy
39        .new_with_children(
40            taffy::style::Style {
41                align_items: Some(taffy::style::AlignItems::Baseline),
42                size: taffy::geometry::Size {
43                    width: taffy::style::Dimension::Length(100f32),
44                    height: taffy::style::Dimension::Length(100f32),
45                },
46                ..Default::default()
47            },
48            &[node0, node1],
49        )
50        .unwrap();
51    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
52    println!("\nComputed tree:");
53    taffy::util::print_tree(&taffy, node);
54    println!();
55    let Layout { size, location, .. } = taffy.layout(node).unwrap();
56    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
57    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
58    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
59    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
60    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
61    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
62    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
63    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
64    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
65    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
66    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
67    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1, 20f32, size.height);
68    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
69    assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node1, 30f32, location.y);
70    let Layout { size, location, .. } = taffy.layout(node10).unwrap();
71    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node10, 50f32, size.width);
72    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node10, 10f32, size.height);
73    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node10, 0f32, location.x);
74    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node10, 0f32, location.y);
75}