gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 499HTML 238Markdown 7TOML 31442 Definiciones

⎇ 0.4.x tests/generated/grid/grid_auto_takes_precedence_over_fr.rs Rust · 99 líneas · 4.1 KB Historia Quién tocó qué crudo

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

1#[test]
2fn grid_auto_takes_precedence_over_fr() {
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(taffy::style::Style { ..Default::default() }).unwrap();
7    let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
8    let node = taffy
9        .new_with_children(
10            taffy::style::Style {
11                display: taffy::style::Display::Grid,
12                grid_template_rows: vec![length(40f32)],
13                grid_template_columns: vec![auto(), fr(1f32)],
14                size: taffy::geometry::Size {
15                    width: taffy::style::Dimension::Length(200f32),
16                    height: taffy::style::Dimension::Length(200f32),
17                },
18                ..Default::default()
19            },
20            &[node0, node1],
21        )
22        .unwrap();
23    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
24    println!("\nComputed tree:");
25    taffy.print_tree(node);
26    println!();
27    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
28    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
29    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
30    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
31    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
32    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
33    #[cfg(feature = "content_size")]
34    assert_eq!(
35        layout.scroll_width(),
36        0f32,
37        "scroll_width of node {:?}. Expected {}. Actual {}",
38        node,
39        0f32,
40        layout.scroll_width()
41    );
42    #[cfg(feature = "content_size")]
43    assert_eq!(
44        layout.scroll_height(),
45        0f32,
46        "scroll_height of node {:?}. Expected {}. Actual {}",
47        node,
48        0f32,
49        layout.scroll_height()
50    );
51    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
52    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
53    assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node0, 0f32, size.width);
54    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
55    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
56    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
57    #[cfg(feature = "content_size")]
58    assert_eq!(
59        layout.scroll_width(),
60        0f32,
61        "scroll_width of node {:?}. Expected {}. Actual {}",
62        node0,
63        0f32,
64        layout.scroll_width()
65    );
66    #[cfg(feature = "content_size")]
67    assert_eq!(
68        layout.scroll_height(),
69        0f32,
70        "scroll_height of node {:?}. Expected {}. Actual {}",
71        node0,
72        0f32,
73        layout.scroll_height()
74    );
75    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
76    let layout @ Layout { size, location, .. } = taffy.layout(node1).unwrap();
77    assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node1, 200f32, size.width);
78    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
79    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
80    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
81    #[cfg(feature = "content_size")]
82    assert_eq!(
83        layout.scroll_width(),
84        0f32,
85        "scroll_width of node {:?}. Expected {}. Actual {}",
86        node1,
87        0f32,
88        layout.scroll_width()
89    );
90    #[cfg(feature = "content_size")]
91    assert_eq!(
92        layout.scroll_height(),
93        0f32,
94        "scroll_height of node {:?}. Expected {}. Actual {}",
95        node1,
96        0f32,
97        layout.scroll_height()
98    );
99}