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