Grid/refactor coordinate handling (#301)
1#[test]
2fn grid_justify_items_sized_end() {
3 use slotmap::Key;
4 #[allow(unused_imports)]
5 use taffy::{layout::Layout, prelude::*};
6 let mut taffy = taffy::Taffy::new();
7 let node0 = taffy
8 .new_leaf(taffy::style::Style {
9 grid_row: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
10 grid_column: taffy::geometry::Line { start: line(1i16), end: taffy::style::GridPlacement::Auto },
11 size: taffy::geometry::Size {
12 width: taffy::style::Dimension::Points(20f32),
13 height: taffy::style::Dimension::Points(20f32),
14 },
15 ..Default::default()
16 })
17 .unwrap();
18 let node1 = taffy
19 .new_leaf(taffy::style::Style {
20 grid_row: taffy::geometry::Line { start: line(3i16), end: taffy::style::GridPlacement::Auto },
21 grid_column: taffy::geometry::Line { start: line(3i16), end: taffy::style::GridPlacement::Auto },
22 size: taffy::geometry::Size {
23 width: taffy::style::Dimension::Points(60f32),
24 height: taffy::style::Dimension::Points(60f32),
25 },
26 ..Default::default()
27 })
28 .unwrap();
29 let node = taffy
30 .new_with_children(
31 taffy::style::Style {
32 display: taffy::style::Display::Grid,
33 justify_items: Some(taffy::style::JustifyItems::End),
34 grid_template_rows: vec![points(40f32), points(40f32), points(40f32)],
35 grid_template_columns: vec![points(40f32), points(40f32), points(40f32)],
36 size: taffy::geometry::Size {
37 width: taffy::style::Dimension::Points(120f32),
38 height: taffy::style::Dimension::Points(120f32),
39 },
40 ..Default::default()
41 },
42 &[node0, node1],
43 )
44 .unwrap();
45 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
46 println!("\nComputed tree:");
47 taffy::debug::print_tree(&taffy, node);
48 println!();
49 let Layout { size, location, .. } = taffy.layout(node).unwrap();
50 assert_eq!(size.width, 120f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 120f32, size.width);
51 assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 120f32, size.height);
52 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
53 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
54 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
55 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.width);
56 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height);
57 assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, location.x);
58 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
59 let Layout { size, location, .. } = taffy.layout(node1).unwrap();
60 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 60f32, size.width);
61 assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 60f32, size.height);
62 assert_eq!(location.x, 60f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 60f32, location.x);
63 assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 80f32, location.y);
64}