⎇ 568f643327ec6b4879df0087def7f4e66b6acafb
tests/generated/block_absolute_child_with_max_height.rs
Historia
Quién tocó qué
crudo
Implement CSS Block layout (`Display::Block`) (#474)
1#[test]
2fn block_absolute_child_with_max_height() {
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 display: taffy::style::Display::Block,
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::Length(100f32),
11 height: taffy::style::Dimension::Length(150f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node0 = taffy
17 .new_with_children(
18 taffy::style::Style {
19 display: taffy::style::Display::Block,
20 position: taffy::style::Position::Absolute,
21 max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(100f32) },
22 inset: taffy::geometry::Rect {
23 left: auto(),
24 right: auto(),
25 top: auto(),
26 bottom: taffy::style::LengthPercentageAuto::Length(20f32),
27 },
28 ..Default::default()
29 },
30 &[node00],
31 )
32 .unwrap();
33 let node = taffy
34 .new_with_children(
35 taffy::style::Style {
36 display: taffy::style::Display::Block,
37 size: taffy::geometry::Size {
38 width: taffy::style::Dimension::Length(100f32),
39 height: taffy::style::Dimension::Length(200f32),
40 },
41 ..Default::default()
42 },
43 &[node0],
44 )
45 .unwrap();
46 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
47 println!("\nComputed tree:");
48 taffy::util::print_tree(&taffy, node);
49 println!();
50 let Layout { size, location, .. } = taffy.layout(node).unwrap();
51 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
52 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
53 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
54 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
55 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
56 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
57 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
58 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
59 assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node0, 80f32, location.y);
60 let Layout { size, location, .. } = taffy.layout(node00).unwrap();
61 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node00, 100f32, size.width);
62 assert_eq!(size.height, 150f32, "height of node {:?}. Expected {}. Actual {}", node00, 150f32, size.height);
63 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
64 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
65}