⎇ 568f643327ec6b4879df0087def7f4e66b6acafb
tests/generated/margin_auto_top_and_bottom_stretch.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Rename `Points`/`points` to `Length`/`length` in many APIs (#459)
1#[test]
2fn margin_auto_top_and_bottom_stretch() {
3 #[allow(unused_imports)]
4 use taffy::{prelude::*, tree::Layout};
5 let mut taffy = taffy::Taffy::new();
6 let node0 = taffy
7 .new_leaf(taffy::style::Style {
8 size: taffy::geometry::Size {
9 width: taffy::style::Dimension::Length(50f32),
10 height: taffy::style::Dimension::Length(50f32),
11 },
12 margin: taffy::geometry::Rect {
13 left: zero(),
14 right: zero(),
15 top: taffy::style::LengthPercentageAuto::Auto,
16 bottom: taffy::style::LengthPercentageAuto::Auto,
17 },
18 ..Default::default()
19 })
20 .unwrap();
21 let node1 = taffy
22 .new_leaf(taffy::style::Style {
23 size: taffy::geometry::Size {
24 width: taffy::style::Dimension::Length(50f32),
25 height: taffy::style::Dimension::Length(50f32),
26 },
27 ..Default::default()
28 })
29 .unwrap();
30 let node = taffy
31 .new_with_children(
32 taffy::style::Style {
33 flex_direction: taffy::style::FlexDirection::Column,
34 align_items: Some(taffy::style::AlignItems::Stretch),
35 size: taffy::geometry::Size {
36 width: taffy::style::Dimension::Length(200f32),
37 height: taffy::style::Dimension::Length(200f32),
38 },
39 ..Default::default()
40 },
41 &[node0, node1],
42 )
43 .unwrap();
44 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
45 println!("\nComputed tree:");
46 taffy::util::print_tree(&taffy, node);
47 println!();
48 let Layout { size, location, .. } = taffy.layout(node).unwrap();
49 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
50 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
51 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
52 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
53 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
54 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
55 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
56 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
57 assert_eq!(location.y, 50f32, "y of node {:?}. Expected {}. Actual {}", node0, 50f32, location.y);
58 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
59 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
60 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1, 50f32, size.height);
61 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
62 assert_eq!(location.y, 150f32, "y of node {:?}. Expected {}. Actual {}", node1, 150f32, location.y);
63}