gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definiciones

⎇ 0.5.x tests/generated/flex/padding_align_end_child.rs Rust · 87 líneas · 3.5 KB Historia Quién tocó qué crudo

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

1#[test]
2fn padding_align_end_child() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6    let node0 = taffy
7        .new_leaf(taffy::style::Style {
8            size: taffy::geometry::Size {
9                width: taffy::style::Dimension::Length(100f32),
10                height: taffy::style::Dimension::Length(100f32),
11            },
12            padding: taffy::geometry::Rect {
13                left: taffy::style::LengthPercentage::Length(20f32),
14                right: taffy::style::LengthPercentage::Length(20f32),
15                top: taffy::style::LengthPercentage::Length(20f32),
16                bottom: taffy::style::LengthPercentage::Length(20f32),
17            },
18            ..Default::default()
19        })
20        .unwrap();
21    let node = taffy
22        .new_with_children(
23            taffy::style::Style {
24                align_items: Some(taffy::style::AlignItems::FlexEnd),
25                justify_content: Some(taffy::style::JustifyContent::FlexEnd),
26                size: taffy::geometry::Size {
27                    width: taffy::style::Dimension::Length(200f32),
28                    height: taffy::style::Dimension::Length(200f32),
29                },
30                ..Default::default()
31            },
32            &[node0],
33        )
34        .unwrap();
35    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
36    println!("\nComputed tree:");
37    taffy.print_tree(node);
38    println!();
39    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
40    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
41    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
42    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
43    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
44    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
45    #[cfg(feature = "content_size")]
46    assert_eq!(
47        layout.scroll_width(),
48        0f32,
49        "scroll_width of node {:?}. Expected {}. Actual {}",
50        node,
51        0f32,
52        layout.scroll_width()
53    );
54    #[cfg(feature = "content_size")]
55    assert_eq!(
56        layout.scroll_height(),
57        0f32,
58        "scroll_height of node {:?}. Expected {}. Actual {}",
59        node,
60        0f32,
61        layout.scroll_height()
62    );
63    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
64    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
65    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
66    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
67    assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node0, 100f32, location.x);
68    assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node0, 100f32, location.y);
69    #[cfg(feature = "content_size")]
70    assert_eq!(
71        layout.scroll_width(),
72        0f32,
73        "scroll_width of node {:?}. Expected {}. Actual {}",
74        node0,
75        0f32,
76        layout.scroll_width()
77    );
78    #[cfg(feature = "content_size")]
79    assert_eq!(
80        layout.scroll_height(),
81        0f32,
82        "scroll_height of node {:?}. Expected {}. Actual {}",
83        node0,
84        0f32,
85        layout.scroll_height()
86    );
87}