Reinstate FlexStart and FlexEnd alignment variants (#336)
1#[test]
2fn flex_wrap_wrap_to_child_height() {
3 use slotmap::Key;
4 #[allow(unused_imports)]
5 use taffy::{layout::Layout, prelude::*};
6 let mut taffy = taffy::Taffy::new();
7 let node000 = taffy
8 .new_leaf(taffy::style::Style {
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::Points(100f32),
11 height: taffy::style::Dimension::Points(100f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node00 = taffy
17 .new_with_children(
18 taffy::style::Style {
19 flex_direction: taffy::style::FlexDirection::Column,
20 size: taffy::geometry::Size { width: taffy::style::Dimension::Points(100f32), height: auto() },
21 ..Default::default()
22 },
23 &[node000],
24 )
25 .unwrap();
26 let node0 = taffy
27 .new_with_children(
28 taffy::style::Style {
29 flex_wrap: taffy::style::FlexWrap::Wrap,
30 align_items: Some(taffy::style::AlignItems::FlexStart),
31 ..Default::default()
32 },
33 &[node00],
34 )
35 .unwrap();
36 let node1 = taffy
37 .new_leaf(taffy::style::Style {
38 size: taffy::geometry::Size {
39 width: taffy::style::Dimension::Points(100f32),
40 height: taffy::style::Dimension::Points(100f32),
41 },
42 ..Default::default()
43 })
44 .unwrap();
45 let node = taffy
46 .new_with_children(
47 taffy::style::Style { flex_direction: taffy::style::FlexDirection::Column, ..Default::default() },
48 &[node0, node1],
49 )
50 .unwrap();
51 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
52 println!("\nComputed tree:");
53 taffy::debug::print_tree(&taffy, node);
54 println!();
55 let Layout { size, location, .. } = taffy.layout(node).unwrap();
56 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
57 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.height);
58 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
59 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
60 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
61 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.width);
62 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.height);
63 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
64 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
65 let Layout { size, location, .. } = taffy.layout(node00).unwrap();
66 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node00.data(), 100f32, size.width);
67 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node00.data(), 100f32, size.height);
68 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.x);
69 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00.data(), 0f32, location.y);
70 let Layout { size, location, .. } = taffy.layout(node000).unwrap();
71 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node000.data(), 100f32, size.width);
72 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node000.data(), 100f32, size.height);
73 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000.data(), 0f32, location.x);
74 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node000.data(), 0f32, location.y);
75 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
76 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 100f32, size.width);
77 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 100f32, size.height);
78 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x);
79 assert_eq!(location.y, 100f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 100f32, location.y);
80}