⎇ e8253b1ae8ad9e95777144ce91aa6fb1ec8d4e32
tests/generated/grid_percent_items_width_and_margin.rs
History
Who touched what
raw
Fix percent sized tracks (#314)
1#[test]
2fn grid_percent_items_width_and_margin() {
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 size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.45f32), height: auto() },
10 margin: taffy::geometry::Rect {
11 left: taffy::style::LengthPercentageAuto::Percent(0.05f32),
12 right: taffy::style::LengthPercentageAuto::Percent(0.05f32),
13 top: taffy::style::LengthPercentageAuto::Percent(0.05f32),
14 bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32),
15 },
16 padding: taffy::geometry::Rect {
17 left: taffy::style::LengthPercentage::Points(3f32),
18 right: taffy::style::LengthPercentage::Points(3f32),
19 top: taffy::style::LengthPercentage::Points(3f32),
20 bottom: taffy::style::LengthPercentage::Points(3f32),
21 },
22 ..Default::default()
23 })
24 .unwrap();
25 let node = taffy
26 .new_with_children(
27 taffy::style::Style {
28 display: taffy::style::Display::Grid,
29 size: taffy::geometry::Size { width: taffy::style::Dimension::Points(200f32), height: auto() },
30 padding: taffy::geometry::Rect {
31 left: taffy::style::LengthPercentage::Points(3f32),
32 right: taffy::style::LengthPercentage::Points(3f32),
33 top: taffy::style::LengthPercentage::Points(3f32),
34 bottom: taffy::style::LengthPercentage::Points(3f32),
35 },
36 ..Default::default()
37 },
38 &[node0],
39 )
40 .unwrap();
41 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
42 println!("\nComputed tree:");
43 taffy::debug::print_tree(&taffy, node);
44 println!();
45 let Layout { size, location, .. } = taffy.layout(node).unwrap();
46 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.width);
47 assert_eq!(size.height, 31f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 31f32, size.height);
48 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
49 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
50 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
51 assert_eq!(size.width, 87f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 87f32, size.width);
52 assert_eq!(size.height, 6f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 6f32, size.height);
53 assert_eq!(location.x, 13f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 13f32, location.x);
54 assert_eq!(location.y, 13f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 13f32, location.y);
55}