tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 499HTML 238Markdown 7TOML 41214 Definitions

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/flex/flex_basis_smaller_than_main_dimen_column.rs Rust · 89 lines · 4.4 KB History Who touched what raw

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

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