gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 231Rust 9TOML 3CSS 1344 Definiciones

⎇ c154b8aa719da0d6f8636b123765a47fa40a3306 tests/generated/flex/measure_child_constraint_padding_parent.rs Rust · 77 líneas · 3.5 KB Historia Quién tocó qué crudo

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

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