Rename FlexboxLayout back to Style (#251)
1use taffy::{geometry::Point, layout::AvailableSpace, style::Dimension};
2
3#[test]
4fn simple_child() {
5 let mut taffy = taffy::Taffy::new();
6 let node0_0 = taffy
7 .new_leaf(taffy::style::Style {
8 align_self: taffy::prelude::AlignSelf::Center,
9 size: taffy::geometry::Size { width: Dimension::Points(10f32), height: Dimension::Points(10f32) },
10 ..Default::default()
11 })
12 .unwrap();
13 let node0 = taffy
14 .new_with_children(
15 taffy::style::Style {
16 size: taffy::geometry::Size { width: Dimension::Points(10f32), height: Dimension::Points(10f32) },
17 ..Default::default()
18 },
19 &[node0_0],
20 )
21 .unwrap();
22 let node1_0 = taffy
23 .new_leaf(taffy::style::Style {
24 align_self: taffy::prelude::AlignSelf::Center,
25 size: taffy::geometry::Size { width: Dimension::Points(10f32), height: Dimension::Points(10f32) },
26 ..Default::default()
27 })
28 .unwrap();
29 let node1_1 = taffy
30 .new_leaf(taffy::style::Style {
31 align_self: taffy::prelude::AlignSelf::Center,
32 size: taffy::geometry::Size { width: Dimension::Points(10f32), height: Dimension::Points(10f32) },
33 ..Default::default()
34 })
35 .unwrap();
36 let node1 = taffy
37 .new_with_children(
38 taffy::style::Style {
39 size: taffy::geometry::Size { width: Dimension::Undefined, height: Dimension::Undefined },
40 ..Default::default()
41 },
42 &[node1_0, node1_1],
43 )
44 .unwrap();
45 let node = taffy
46 .new_with_children(
47 taffy::style::Style {
48 size: taffy::geometry::Size { width: Dimension::Percent(100.0), height: Dimension::Percent(100.0) },
49 ..Default::default()
50 },
51 &[node0, node1],
52 )
53 .unwrap();
54 taffy
55 .compute_layout(
56 node,
57 taffy::geometry::Size { width: AvailableSpace::Definite(100.), height: AvailableSpace::Definite(100.) },
58 )
59 .unwrap();
60 assert_eq!(taffy.layout(node).unwrap().location, Point { x: 0.0, y: 0.0 });
61 assert_eq!(taffy.layout(node0).unwrap().location, Point { x: 0.0, y: 0.0 });
62 assert_eq!(taffy.layout(node1).unwrap().location, Point { x: 10.0, y: 0.0 });
63 assert_eq!(taffy.layout(node0_0).unwrap().location, Point { x: 0.0, y: 0.0 });
64 // Layout is relative so node1_0 location starts at (0,0) and is not ofset by it's parent location
65 assert_eq!(taffy.layout(node1_0).unwrap().location, Point { x: 00.0, y: 0.0 });
66 assert_eq!(taffy.layout(node1_1).unwrap().location, Point { x: 10.0, y: 0.0 });
67}