gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1108HTML 1039Markdown 12TOML 74481 Definiciones

⎇ c154b8aa719da0d6f8636b123765a47fa40a3306 tests/generated/flex/measure_child.rs Rust · 69 líneas · 2.8 KB Historia Quién tocó qué crudo

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

1#[test]
2fn measure_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_with_context(
8            taffy::style::Style { ..Default::default() },
9            crate::TextMeasure {
10                text_content: "HHHHHH",
11                writing_mode: crate::WritingMode::Horizontal,
12                _aspect_ratio: None,
13            },
14        )
15        .unwrap();
16    let node = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node0]).unwrap();
17    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
18    println!("\nComputed tree:");
19    taffy.print_tree(node);
20    println!();
21    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
22    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
23    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node, 60f32, size.width);
24    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node, 10f32, size.height);
25    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
26    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
27    #[cfg(feature = "content_size")]
28    assert_eq!(
29        layout.scroll_width(),
30        0f32,
31        "scroll_width of node {:?}. Expected {}. Actual {}",
32        node,
33        0f32,
34        layout.scroll_width()
35    );
36    #[cfg(feature = "content_size")]
37    assert_eq!(
38        layout.scroll_height(),
39        0f32,
40        "scroll_height of node {:?}. Expected {}. Actual {}",
41        node,
42        0f32,
43        layout.scroll_height()
44    );
45    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
46    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
47    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0, 60f32, size.width);
48    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
49    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
50    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
51    #[cfg(feature = "content_size")]
52    assert_eq!(
53        layout.scroll_width(),
54        0f32,
55        "scroll_width of node {:?}. Expected {}. Actual {}",
56        node0,
57        0f32,
58        layout.scroll_width()
59    );
60    #[cfg(feature = "content_size")]
61    assert_eq!(
62        layout.scroll_height(),
63        0f32,
64        "scroll_height of node {:?}. Expected {}. Actual {}",
65        node0,
66        0f32,
67        layout.scroll_height()
68    );
69}