tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Sutichaykuna

⎇ 368b7da13d700e20ed1ef0fa2399fade0ca5ea3f tests/generated/flex/scroll_size.rs Rust · 143 siq'ikuna · 5.9 KB Ñawpa willay Pi imata llamkarqan ch'uya

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

1#[test]
2#[allow(non_snake_case)]
3fn scroll_size__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_shrink: 0f32,
10            size: taffy::geometry::Size {
11                width: taffy::style::Dimension::from_length(100f32),
12                height: taffy::style::Dimension::from_length(100f32),
13            },
14            ..Default::default()
15        })
16        .unwrap();
17    let node = taffy
18        .new_with_children(
19            taffy::style::Style {
20                overflow: taffy::geometry::Point {
21                    x: taffy::style::Overflow::Scroll,
22                    y: taffy::style::Overflow::Scroll,
23                },
24                scrollbar_width: 15f32,
25                align_items: Some(taffy::style::AlignItems::Start),
26                justify_content: Some(taffy::style::JustifyContent::Start),
27                size: taffy::geometry::Size {
28                    width: taffy::style::Dimension::from_length(50f32),
29                    height: taffy::style::Dimension::from_length(50f32),
30                },
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, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
43    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, 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    #[cfg(feature = "content_size")]
47    assert_eq!(
48        layout.scroll_width(),
49        65f32,
50        "scroll_width of node {:?}. Expected {}. Actual {}",
51        node,
52        65f32,
53        layout.scroll_width()
54    );
55    #[cfg(feature = "content_size")]
56    assert_eq!(
57        layout.scroll_height(),
58        65f32,
59        "scroll_height of node {:?}. Expected {}. Actual {}",
60        node,
61        65f32,
62        layout.scroll_height()
63    );
64    let layout = taffy.layout(node0).unwrap();
65    let Layout { size, location, .. } = layout;
66    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
67    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
68    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
69    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
70}
71
72#[test]
73#[allow(non_snake_case)]
74fn scroll_size__content_box() {
75    #[allow(unused_imports)]
76    use taffy::{prelude::*, Layout};
77    let mut taffy = crate::new_test_tree();
78    let node0 = taffy
79        .new_leaf(taffy::style::Style {
80            box_sizing: taffy::style::BoxSizing::ContentBox,
81            flex_shrink: 0f32,
82            size: taffy::geometry::Size {
83                width: taffy::style::Dimension::from_length(100f32),
84                height: taffy::style::Dimension::from_length(100f32),
85            },
86            ..Default::default()
87        })
88        .unwrap();
89    let node = taffy
90        .new_with_children(
91            taffy::style::Style {
92                box_sizing: taffy::style::BoxSizing::ContentBox,
93                overflow: taffy::geometry::Point {
94                    x: taffy::style::Overflow::Scroll,
95                    y: taffy::style::Overflow::Scroll,
96                },
97                scrollbar_width: 15f32,
98                align_items: Some(taffy::style::AlignItems::Start),
99                justify_content: Some(taffy::style::JustifyContent::Start),
100                size: taffy::geometry::Size {
101                    width: taffy::style::Dimension::from_length(50f32),
102                    height: taffy::style::Dimension::from_length(50f32),
103                },
104                ..Default::default()
105            },
106            &[node0],
107        )
108        .unwrap();
109    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
110    println!("\nComputed tree:");
111    taffy.print_tree(node);
112    println!();
113    let layout = taffy.layout(node).unwrap();
114    let Layout { size, location, .. } = layout;
115    assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
116    assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
117    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
118    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
119    #[cfg(feature = "content_size")]
120    assert_eq!(
121        layout.scroll_width(),
122        65f32,
123        "scroll_width of node {:?}. Expected {}. Actual {}",
124        node,
125        65f32,
126        layout.scroll_width()
127    );
128    #[cfg(feature = "content_size")]
129    assert_eq!(
130        layout.scroll_height(),
131        65f32,
132        "scroll_height of node {:?}. Expected {}. Actual {}",
133        node,
134        65f32,
135        layout.scroll_height()
136    );
137    let layout = taffy.layout(node0).unwrap();
138    let Layout { size, location, .. } = layout;
139    assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
140    assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
141    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
142    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
143}