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