tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81414 Definiciones

⎇ float-layout tests/generated/flex/flex_basis_smaller_than_content_column.rs Rust · 120 líneas · 6.0 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 flex_basis_smaller_than_content_column__border_box() {
4    #[allow(unused_imports)]
5    use taffy::{prelude::*, Layout};
6    let mut taffy = crate::new_test_tree();
7    let node00 = taffy
8        .new_leaf(taffy::style::Style {
9            size: taffy::geometry::Size {
10                width: taffy::style::Dimension::from_length(100f32),
11                height: taffy::style::Dimension::from_length(100f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node0 = taffy
17        .new_with_children(
18            taffy::style::Style {
19                flex_direction: taffy::style::FlexDirection::Column,
20                flex_basis: taffy::style::Dimension::from_length(50f32),
21                ..Default::default()
22            },
23            &[node00],
24        )
25        .unwrap();
26    let node = taffy
27        .new_with_children(
28            taffy::style::Style {
29                flex_direction: taffy::style::FlexDirection::Column,
30                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(100f32) },
31                ..Default::default()
32            },
33            &[node0],
34        )
35        .unwrap();
36    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
37    println!("\nComputed tree:");
38    taffy.print_tree(node);
39    println!();
40    let layout = taffy.layout(node).unwrap();
41    let Layout { size, location, .. } = layout;
42    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
43    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
44    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
45    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
46    let layout = taffy.layout(node0).unwrap();
47    let Layout { size, location, .. } = layout;
48    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
49    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
50    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
51    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
52    let layout = taffy.layout(node00).unwrap();
53    let Layout { size, location, .. } = layout;
54    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node00, 100f32, size.width);
55    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node00, 100f32, size.height);
56    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
57    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
58}
59
60#[test]
61#[allow(non_snake_case)]
62fn flex_basis_smaller_than_content_column__content_box() {
63    #[allow(unused_imports)]
64    use taffy::{prelude::*, Layout};
65    let mut taffy = crate::new_test_tree();
66    let node00 = taffy
67        .new_leaf(taffy::style::Style {
68            box_sizing: taffy::style::BoxSizing::ContentBox,
69            size: taffy::geometry::Size {
70                width: taffy::style::Dimension::from_length(100f32),
71                height: taffy::style::Dimension::from_length(100f32),
72            },
73            ..Default::default()
74        })
75        .unwrap();
76    let node0 = taffy
77        .new_with_children(
78            taffy::style::Style {
79                box_sizing: taffy::style::BoxSizing::ContentBox,
80                flex_direction: taffy::style::FlexDirection::Column,
81                flex_basis: taffy::style::Dimension::from_length(50f32),
82                ..Default::default()
83            },
84            &[node00],
85        )
86        .unwrap();
87    let node = taffy
88        .new_with_children(
89            taffy::style::Style {
90                box_sizing: taffy::style::BoxSizing::ContentBox,
91                flex_direction: taffy::style::FlexDirection::Column,
92                size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(100f32) },
93                ..Default::default()
94            },
95            &[node0],
96        )
97        .unwrap();
98    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
99    println!("\nComputed tree:");
100    taffy.print_tree(node);
101    println!();
102    let layout = taffy.layout(node).unwrap();
103    let Layout { size, location, .. } = layout;
104    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
105    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
106    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
107    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
108    let layout = taffy.layout(node0).unwrap();
109    let Layout { size, location, .. } = layout;
110    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
111    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
112    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
113    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
114    let layout = taffy.layout(node00).unwrap();
115    let Layout { size, location, .. } = layout;
116    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node00, 100f32, size.width);
117    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node00, 100f32, size.height);
118    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
119    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
120}