tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1100HTML 1031Markdown 12TOML 84455 Definiciones

⎇ float-layout tests/generated/grid/grid_minmax_column_with_fr_fixed.rs Rust · 92 líneas · 5.3 KB Historia Quién tocó qué crudo

Use tagged pointer to represent size/length values (#769) afa6437b0 · Nico Burns ·

1#[test]
2#[allow(non_snake_case)]
3fn grid_minmax_column_with_fr_fixed__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node0 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
8    let node1 = taffy.new_leaf(taffy::style::Style { ..Default::default() }).unwrap();
9    let node = taffy
10        .new_with_children(
11            taffy::style::Style {
12                display: taffy::style::Display::Grid,
13                grid_template_rows: vec![length(40f32)],
14                grid_template_columns: vec![minmax(length(20f32), length(40f32)), fr(1f32)],
15                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(60f32), height: auto() },
16                ..Default::default()
17            },
18            &[node0, node1],
19        )
20        .unwrap();
21    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
22    println!("\nComputed tree:");
23    taffy.print_tree(node);
24    println!();
25    let layout = taffy.layout(node).unwrap();
26    let Layout { size, location, .. } = layout;
27    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node, 60f32, size.width);
28    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, size.height);
29    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
30    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
31    let layout = taffy.layout(node0).unwrap();
32    let Layout { size, location, .. } = layout;
33    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
34    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
35    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
36    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
37    let layout = taffy.layout(node1).unwrap();
38    let Layout { size, location, .. } = layout;
39    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
40    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
41    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1, 40f32, location.x);
42    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
43}
44
45#[test]
46#[allow(non_snake_case)]
47fn grid_minmax_column_with_fr_fixed__content_box() {
48    #[allow(unused_imports)]
49    use taffy::{prelude::*, Layout};
50    let mut taffy = crate::new_test_tree();
51    let node0 = taffy
52        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
53        .unwrap();
54    let node1 = taffy
55        .new_leaf(taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() })
56        .unwrap();
57    let node = taffy
58        .new_with_children(
59            taffy::style::Style {
60                display: taffy::style::Display::Grid,
61                box_sizing: taffy::style::BoxSizing::ContentBox,
62                grid_template_rows: vec![length(40f32)],
63                grid_template_columns: vec![minmax(length(20f32), length(40f32)), fr(1f32)],
64                size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(60f32), height: auto() },
65                ..Default::default()
66            },
67            &[node0, node1],
68        )
69        .unwrap();
70    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
71    println!("\nComputed tree:");
72    taffy.print_tree(node);
73    println!();
74    let layout = taffy.layout(node).unwrap();
75    let Layout { size, location, .. } = layout;
76    assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node, 60f32, size.width);
77    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, size.height);
78    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
79    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
80    let layout = taffy.layout(node0).unwrap();
81    let Layout { size, location, .. } = layout;
82    assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0, 40f32, size.width);
83    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
84    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
85    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
86    let layout = taffy.layout(node1).unwrap();
87    let Layout { size, location, .. } = layout;
88    assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
89    assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node1, 40f32, size.height);
90    assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1, 40f32, location.x);
91    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
92}