gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1100HTML 1031Markdown 12TOML 84455 Definiciones

⎇ 0.5.x tests/generated/flex/flex_basis_larger_than_content_row.rs Rust · 110 líneas · 4.3 KB Historia Quién tocó qué crudo

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

1#[test]
2fn flex_basis_larger_than_content_row() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6    let node00 = taffy
7        .new_leaf(taffy::style::Style {
8            size: taffy::geometry::Size {
9                width: taffy::style::Dimension::Length(10f32),
10                height: taffy::style::Dimension::Length(100f32),
11            },
12            ..Default::default()
13        })
14        .unwrap();
15    let node0 = taffy
16        .new_with_children(
17            taffy::style::Style {
18                flex_direction: taffy::style::FlexDirection::Column,
19                flex_basis: taffy::style::Dimension::Length(50f32),
20                ..Default::default()
21            },
22            &[node00],
23        )
24        .unwrap();
25    let node = taffy
26        .new_with_children(
27            taffy::style::Style {
28                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(100f32), height: auto() },
29                ..Default::default()
30            },
31            &[node0],
32        )
33        .unwrap();
34    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
35    println!("\nComputed tree:");
36    taffy.print_tree(node);
37    println!();
38    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
39    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
40    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
41    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
42    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
43    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
44    #[cfg(feature = "content_size")]
45    assert_eq!(
46        layout.scroll_width(),
47        0f32,
48        "scroll_width of node {:?}. Expected {}. Actual {}",
49        node,
50        0f32,
51        layout.scroll_width()
52    );
53    #[cfg(feature = "content_size")]
54    assert_eq!(
55        layout.scroll_height(),
56        0f32,
57        "scroll_height of node {:?}. Expected {}. Actual {}",
58        node,
59        0f32,
60        layout.scroll_height()
61    );
62    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
63    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
64    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
65    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
66    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
67    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
68    #[cfg(feature = "content_size")]
69    assert_eq!(
70        layout.scroll_width(),
71        0f32,
72        "scroll_width of node {:?}. Expected {}. Actual {}",
73        node0,
74        0f32,
75        layout.scroll_width()
76    );
77    #[cfg(feature = "content_size")]
78    assert_eq!(
79        layout.scroll_height(),
80        0f32,
81        "scroll_height of node {:?}. Expected {}. Actual {}",
82        node0,
83        0f32,
84        layout.scroll_height()
85    );
86    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
87    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
88    assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node00, 10f32, size.width);
89    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node00, 100f32, size.height);
90    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
91    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
92    #[cfg(feature = "content_size")]
93    assert_eq!(
94        layout.scroll_width(),
95        0f32,
96        "scroll_width of node {:?}. Expected {}. Actual {}",
97        node00,
98        0f32,
99        layout.scroll_width()
100    );
101    #[cfg(feature = "content_size")]
102    assert_eq!(
103        layout.scroll_height(),
104        0f32,
105        "scroll_height of node {:?}. Expected {}. Actual {}",
106        node00,
107        0f32,
108        layout.scroll_height()
109    );
110}