tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1090HTML 1022Markdown 12TOML 84418 Definitions

⎇ f99b57fbad456aa2756b374ff40c876e4b9574c2 tests/generated/flex/absolute_child_with_max_height.rs Rust · 130 lines · 6.6 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 absolute_child_with_max_height__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(30f32),
12            },
13            ..Default::default()
14        })
15        .unwrap();
16    let node0 = taffy
17        .new_with_children(
18            taffy::style::Style {
19                position: taffy::style::Position::Absolute,
20                flex_direction: taffy::style::FlexDirection::Column,
21                max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(100f32) },
22                inset: taffy::geometry::Rect { left: auto(), right: auto(), top: auto(), bottom: length(20f32) },
23                ..Default::default()
24            },
25            &[node00],
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::from_length(100f32),
34                    height: taffy::style::Dimension::from_length(200f32),
35                },
36                ..Default::default()
37            },
38            &[node0],
39        )
40        .unwrap();
41    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
42    println!("\nComputed tree:");
43    taffy.print_tree(node);
44    println!();
45    let layout = taffy.layout(node).unwrap();
46    let Layout { size, location, .. } = layout;
47    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
48    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
49    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
50    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
51    let layout = taffy.layout(node0).unwrap();
52    let Layout { size, location, .. } = layout;
53    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
54    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node0, 30f32, size.height);
55    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
56    assert_eq!(location.y, 150f32, "y of node {:?}. Expected {}. Actual {}", node0, 150f32, location.y);
57    let layout = taffy.layout(node00).unwrap();
58    let Layout { size, location, .. } = layout;
59    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node00, 100f32, size.width);
60    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node00, 30f32, size.height);
61    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
62    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
63}
64
65#[test]
66#[allow(non_snake_case)]
67fn absolute_child_with_max_height__content_box() {
68    #[allow(unused_imports)]
69    use taffy::{prelude::*, Layout};
70    let mut taffy = crate::new_test_tree();
71    let node00 = taffy
72        .new_leaf(taffy::style::Style {
73            box_sizing: taffy::style::BoxSizing::ContentBox,
74            size: taffy::geometry::Size {
75                width: taffy::style::Dimension::from_length(100f32),
76                height: taffy::style::Dimension::from_length(30f32),
77            },
78            ..Default::default()
79        })
80        .unwrap();
81    let node0 = taffy
82        .new_with_children(
83            taffy::style::Style {
84                box_sizing: taffy::style::BoxSizing::ContentBox,
85                position: taffy::style::Position::Absolute,
86                flex_direction: taffy::style::FlexDirection::Column,
87                max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::from_length(100f32) },
88                inset: taffy::geometry::Rect { left: auto(), right: auto(), top: auto(), bottom: length(20f32) },
89                ..Default::default()
90            },
91            &[node00],
92        )
93        .unwrap();
94    let node = taffy
95        .new_with_children(
96            taffy::style::Style {
97                box_sizing: taffy::style::BoxSizing::ContentBox,
98                flex_direction: taffy::style::FlexDirection::Column,
99                size: taffy::geometry::Size {
100                    width: taffy::style::Dimension::from_length(100f32),
101                    height: taffy::style::Dimension::from_length(200f32),
102                },
103                ..Default::default()
104            },
105            &[node0],
106        )
107        .unwrap();
108    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
109    println!("\nComputed tree:");
110    taffy.print_tree(node);
111    println!();
112    let layout = taffy.layout(node).unwrap();
113    let Layout { size, location, .. } = layout;
114    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
115    assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
116    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
117    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
118    let layout = taffy.layout(node0).unwrap();
119    let Layout { size, location, .. } = layout;
120    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
121    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node0, 30f32, size.height);
122    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
123    assert_eq!(location.y, 150f32, "y of node {:?}. Expected {}. Actual {}", node0, 150f32, location.y);
124    let layout = taffy.layout(node00).unwrap();
125    let Layout { size, location, .. } = layout;
126    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node00, 100f32, size.width);
127    assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node00, 30f32, size.height);
128    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
129    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
130}