gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5334Rust 85Markdown 12TOML 91813 Definiciones

⎇ 0.5.x tests/generated/flex/max_height.rs Rust · 77 líneas · 3.1 KB Historia Quién tocó qué crudo

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

1#[test]
2fn max_height() {
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 { width: taffy::style::Dimension::Length(10f32), height: auto() },
9            max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(50f32) },
10            ..Default::default()
11        })
12        .unwrap();
13    let node = taffy
14        .new_with_children(
15            taffy::style::Style {
16                size: taffy::geometry::Size {
17                    width: taffy::style::Dimension::Length(100f32),
18                    height: taffy::style::Dimension::Length(100f32),
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, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
32    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, 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        0f32,
39        "scroll_width of node {:?}. Expected {}. Actual {}",
40        node,
41        0f32,
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, 10f32, "width of node {:?}. Expected {}. Actual {}", node0, 10f32, size.width);
56    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
57    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
58    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, 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}