gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 492HTML 245JavaScript 8CSS 61138 Definiciones

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/align_content_stretch_row_with_min_height.rs Rust · 85 líneas · 5.0 KB Historia Quién tocó qué crudo

Rename `Points`/`points` to `Length`/`length` in many APIs (#459) 55abeaf2e · Simon Sapin ·

1#[test]
2fn align_content_stretch_row_with_min_height() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout};
5    let mut taffy = taffy::Taffy::new();
6    let node0 = taffy
7        .new_leaf(taffy::style::Style {
8            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
9            ..Default::default()
10        })
11        .unwrap();
12    let node1 = taffy
13        .new_leaf(taffy::style::Style {
14            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
15            min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(80f32) },
16            ..Default::default()
17        })
18        .unwrap();
19    let node2 = taffy
20        .new_leaf(taffy::style::Style {
21            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
22            ..Default::default()
23        })
24        .unwrap();
25    let node3 = taffy
26        .new_leaf(taffy::style::Style {
27            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
28            ..Default::default()
29        })
30        .unwrap();
31    let node4 = taffy
32        .new_leaf(taffy::style::Style {
33            size: taffy::geometry::Size { width: taffy::style::Dimension::Length(50f32), height: auto() },
34            ..Default::default()
35        })
36        .unwrap();
37    let node = taffy
38        .new_with_children(
39            taffy::style::Style {
40                flex_wrap: taffy::style::FlexWrap::Wrap,
41                align_content: Some(taffy::style::AlignContent::Stretch),
42                size: taffy::geometry::Size {
43                    width: taffy::style::Dimension::Length(150f32),
44                    height: taffy::style::Dimension::Length(100f32),
45                },
46                ..Default::default()
47            },
48            &[node0, node1, node2, node3, node4],
49        )
50        .unwrap();
51    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
52    println!("\nComputed tree:");
53    taffy::util::print_tree(&taffy, node);
54    println!();
55    let Layout { size, location, .. } = taffy.layout(node).unwrap();
56    assert_eq!(size.width, 150f32, "width of node {:?}. Expected {}. Actual {}", node, 150f32, size.width);
57    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
58    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
59    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
60    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
61    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
62    assert_eq!(size.height, 90f32, "height of node {:?}. Expected {}. Actual {}", node0, 90f32, size.height);
63    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
64    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
65    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
66    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
67    assert_eq!(size.height, 90f32, "height of node {:?}. Expected {}. Actual {}", node1, 90f32, size.height);
68    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
69    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
70    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
71    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2, 50f32, size.width);
72    assert_eq!(size.height, 90f32, "height of node {:?}. Expected {}. Actual {}", node2, 90f32, size.height);
73    assert_eq!(location.x, 100f32, "x of node {:?}. Expected {}. Actual {}", node2, 100f32, location.x);
74    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node2, 0f32, location.y);
75    let Layout { size, location, .. } = taffy.layout(node3).unwrap();
76    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3, 50f32, size.width);
77    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node3, 10f32, size.height);
78    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node3, 0f32, location.x);
79    assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node3, 90f32, location.y);
80    let Layout { size, location, .. } = taffy.layout(node4).unwrap();
81    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node4, 50f32, size.width);
82    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node4, 10f32, size.height);
83    assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node4, 50f32, location.x);
84    assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node4, 90f32, location.y);
85}