gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 229Rust 8TOML 3CSS 1310 Definiciones

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/block_basic.rs Rust · 47 líneas · 2.5 KB Historia Quién tocó qué crudo

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

1#[test]
2fn block_basic() {
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 { width: taffy::style::Dimension::Length(50f32), height: auto() },
23                ..Default::default()
24            },
25            &[node0, node1],
26        )
27        .unwrap();
28    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
29    println!("\nComputed tree:");
30    taffy::util::print_tree(&taffy, node);
31    println!();
32    let Layout { size, location, .. } = taffy.layout(node).unwrap();
33    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
34    assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node, 20f32, size.height);
35    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
36    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
37    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
38    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
39    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
40    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
41    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
42    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
43    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
44    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
45    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
46    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node1, 10f32, location.y);
47}