gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 695HTML 648Markdown 12TOML 62320 Definiciones

⎇ 568f643327ec6b4879df0087def7f4e66b6acafb tests/generated/rounding_fractial_input_1.rs Rust · 65 líneas · 3.5 KB Historia Quién tocó qué crudo

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

1#[test]
2fn rounding_fractial_input_1() {
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            flex_grow: 1f32,
9            flex_basis: taffy::style::Dimension::Length(50f32),
10            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(20f32) },
11            ..Default::default()
12        })
13        .unwrap();
14    let node1 = taffy
15        .new_leaf(taffy::style::Style {
16            flex_grow: 1f32,
17            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
18            ..Default::default()
19        })
20        .unwrap();
21    let node2 = taffy
22        .new_leaf(taffy::style::Style {
23            flex_grow: 1f32,
24            size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(10f32) },
25            ..Default::default()
26        })
27        .unwrap();
28    let node = taffy
29        .new_with_children(
30            taffy::style::Style {
31                flex_direction: taffy::style::FlexDirection::Column,
32                size: taffy::geometry::Size {
33                    width: taffy::style::Dimension::Length(100f32),
34                    height: taffy::style::Dimension::Length(113.4f32),
35                },
36                ..Default::default()
37            },
38            &[node0, node1, node2],
39        )
40        .unwrap();
41    taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
42    println!("\nComputed tree:");
43    taffy::util::print_tree(&taffy, node);
44    println!();
45    let Layout { size, location, .. } = taffy.layout(node).unwrap();
46    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
47    assert_eq!(size.height, 113f32, "height of node {:?}. Expected {}. Actual {}", node, 113f32, size.height);
48    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
49    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
50    let Layout { size, location, .. } = taffy.layout(node0).unwrap();
51    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
52    assert_eq!(size.height, 64f32, "height of node {:?}. Expected {}. Actual {}", node0, 64f32, size.height);
53    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
54    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
55    let Layout { size, location, .. } = taffy.layout(node1).unwrap();
56    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1, 100f32, size.width);
57    assert_eq!(size.height, 25f32, "height of node {:?}. Expected {}. Actual {}", node1, 25f32, size.height);
58    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
59    assert_eq!(location.y, 64f32, "y of node {:?}. Expected {}. Actual {}", node1, 64f32, location.y);
60    let Layout { size, location, .. } = taffy.layout(node2).unwrap();
61    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node2, 100f32, size.width);
62    assert_eq!(size.height, 24f32, "height of node {:?}. Expected {}. Actual {}", node2, 24f32, size.height);
63    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node2, 0f32, location.x);
64    assert_eq!(location.y, 89f32, "y of node {:?}. Expected {}. Actual {}", node2, 89f32, location.y);
65}