gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 227Rust 7TOML 3CSS 1307 Definiciones

⎇ 0.5.x tests/generated/leaf/leaf_with_content_and_padding.rs Rust · 52 líneas · 2.1 KB Historia Quién tocó qué crudo

Rename Taffy struct to TaffyTree (#580) 17235ffa2 · Nico Burns ·

1#[test]
2fn leaf_with_content_and_padding() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6    let node = taffy
7        .new_leaf_with_context(
8            taffy::style::Style {
9                padding: taffy::geometry::Rect {
10                    left: taffy::style::LengthPercentage::Length(8f32),
11                    right: taffy::style::LengthPercentage::Length(4f32),
12                    top: taffy::style::LengthPercentage::Length(2f32),
13                    bottom: taffy::style::LengthPercentage::Length(6f32),
14                },
15                ..Default::default()
16            },
17            crate::TextMeasure {
18                text_content: "HHHH",
19                writing_mode: crate::WritingMode::Horizontal,
20                _aspect_ratio: None,
21            },
22        )
23        .unwrap();
24    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
25    println!("\nComputed tree:");
26    taffy.print_tree(node);
27    println!();
28    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
29    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
30    assert_eq!(size.width, 52f32, "width of node {:?}. Expected {}. Actual {}", node, 52f32, size.width);
31    assert_eq!(size.height, 18f32, "height of node {:?}. Expected {}. Actual {}", node, 18f32, size.height);
32    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
33    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
34    #[cfg(feature = "content_size")]
35    assert_eq!(
36        layout.scroll_width(),
37        0f32,
38        "scroll_width of node {:?}. Expected {}. Actual {}",
39        node,
40        0f32,
41        layout.scroll_width()
42    );
43    #[cfg(feature = "content_size")]
44    assert_eq!(
45        layout.scroll_height(),
46        0f32,
47        "scroll_height of node {:?}. Expected {}. Actual {}",
48        node,
49        0f32,
50        layout.scroll_height()
51    );
52}