⎇ 0.4.x
tests/generated/grid/grid_percent_items_width_and_padding.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn grid_percent_items_width_and_padding() {
3 #[allow(unused_imports)]
4 use taffy::{prelude::*, tree::Layout, TaffyTree};
5 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6 let node0 = taffy
7 .new_leaf(taffy::style::Style {
8 size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() },
9 padding: taffy::geometry::Rect {
10 left: taffy::style::LengthPercentage::Percent(0.03f32),
11 right: taffy::style::LengthPercentage::Percent(0.03f32),
12 top: taffy::style::LengthPercentage::Percent(0.03f32),
13 bottom: taffy::style::LengthPercentage::Percent(0.03f32),
14 },
15 ..Default::default()
16 })
17 .unwrap();
18 let node = taffy
19 .new_with_children(
20 taffy::style::Style {
21 display: taffy::style::Display::Grid,
22 size: taffy::geometry::Size { width: taffy::style::Dimension::Length(200f32), height: auto() },
23 ..Default::default()
24 },
25 &[node0],
26 )
27 .unwrap();
28 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
29 println!("\nComputed tree:");
30 taffy.print_tree(node);
31 println!();
32 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
33 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
34 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
35 assert_eq!(size.height, 12f32, "height of node {:?}. Expected {}. Actual {}", node, 12f32, size.height);
36 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
37 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
38 #[cfg(feature = "content_size")]
39 assert_eq!(
40 layout.scroll_width(),
41 0f32,
42 "scroll_width of node {:?}. Expected {}. Actual {}",
43 node,
44 0f32,
45 layout.scroll_width()
46 );
47 #[cfg(feature = "content_size")]
48 assert_eq!(
49 layout.scroll_height(),
50 0f32,
51 "scroll_height of node {:?}. Expected {}. Actual {}",
52 node,
53 0f32,
54 layout.scroll_height()
55 );
56 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
57 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
58 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
59 assert_eq!(size.height, 12f32, "height of node {:?}. Expected {}. Actual {}", node0, 12f32, size.height);
60 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
61 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
62 #[cfg(feature = "content_size")]
63 assert_eq!(
64 layout.scroll_width(),
65 0f32,
66 "scroll_width of node {:?}. Expected {}. Actual {}",
67 node0,
68 0f32,
69 layout.scroll_width()
70 );
71 #[cfg(feature = "content_size")]
72 assert_eq!(
73 layout.scroll_height(),
74 0f32,
75 "scroll_height of node {:?}. Expected {}. Actual {}",
76 node0,
77 0f32,
78 layout.scroll_height()
79 );
80}