1#[test]
2fn percent_within_flex_grow() {
3 let mut taffy = taffy::Taffy::new();
4 let node0 = taffy
5 .new_node(
6 taffy::style::Style {
7 size: taffy::geometry::Size { width: taffy::style::Dimension::Points(100f32), ..Default::default() },
8 ..Default::default()
9 },
10 &[],
11 )
12 .unwrap();
13 let node10 = taffy
14 .new_node(
15 taffy::style::Style {
16 size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(1f32), ..Default::default() },
17 ..Default::default()
18 },
19 &[],
20 )
21 .unwrap();
22 let node1 = taffy
23 .new_node(
24 taffy::style::Style {
25 flex_direction: taffy::style::FlexDirection::Column,
26 flex_grow: 1f32,
27 ..Default::default()
28 },
29 &[node10],
30 )
31 .unwrap();
32 let node2 = taffy
33 .new_node(
34 taffy::style::Style {
35 size: taffy::geometry::Size { width: taffy::style::Dimension::Points(100f32), ..Default::default() },
36 ..Default::default()
37 },
38 &[],
39 )
40 .unwrap();
41 let node = taffy
42 .new_node(
43 taffy::style::Style {
44 size: taffy::geometry::Size {
45 width: taffy::style::Dimension::Points(350f32),
46 height: taffy::style::Dimension::Points(100f32),
47 ..Default::default()
48 },
49 ..Default::default()
50 },
51 &[node0, node1, node2],
52 )
53 .unwrap();
54 taffy.compute_layout(node, taffy::geometry::Size::undefined()).unwrap();
55 assert_eq!(taffy.layout(node).unwrap().size.width, 350f32);
56 assert_eq!(taffy.layout(node).unwrap().size.height, 100f32);
57 assert_eq!(taffy.layout(node).unwrap().location.x, 0f32);
58 assert_eq!(taffy.layout(node).unwrap().location.y, 0f32);
59 assert_eq!(taffy.layout(node0).unwrap().size.width, 100f32);
60 assert_eq!(taffy.layout(node0).unwrap().size.height, 100f32);
61 assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32);
62 assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32);
63 assert_eq!(taffy.layout(node1).unwrap().size.width, 150f32);
64 assert_eq!(taffy.layout(node1).unwrap().size.height, 100f32);
65 assert_eq!(taffy.layout(node1).unwrap().location.x, 100f32);
66 assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32);
67 assert_eq!(taffy.layout(node10).unwrap().size.width, 150f32);
68 assert_eq!(taffy.layout(node10).unwrap().size.height, 0f32);
69 assert_eq!(taffy.layout(node10).unwrap().location.x, 0f32);
70 assert_eq!(taffy.layout(node10).unwrap().location.y, 0f32);
71 assert_eq!(taffy.layout(node2).unwrap().size.width, 100f32);
72 assert_eq!(taffy.layout(node2).unwrap().size.height, 100f32);
73 assert_eq!(taffy.layout(node2).unwrap().location.x, 250f32);
74 assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32);
75}