gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 492HTML 245JavaScript 8CSS 61138 Definiciones

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/block_absolute_no_styles.rs Rust · 48 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_absolute_no_styles() {
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(10f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node1 = taffy
17        .new_leaf(taffy::style::Style {
18            display: taffy::style::Display::Block,
19            position: taffy::style::Position::Absolute,
20            ..Default::default()
21        })
22        .unwrap();
23    let node = taffy
24        .new_with_children(
25            taffy::style::Style { display: taffy::style::Display::Block, ..Default::default() },
26            &[node0, node1],
27        )
28        .unwrap();
29    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
30    println!("\nComputed tree:");
31    taffy::util::print_tree(&taffy, node);
32    println!();
33    let Layout { size, location, .. } = taffy.layout(node).unwrap();
34    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
35    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node, 10f32, size.height);
36    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
37    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
38    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
39    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
40    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
41    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
42    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
43    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
44    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node1, 0f32, size.width);
45    assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node1, 0f32, size.height);
46    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
47    assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node1, 10f32, location.y);
48}