⎇ 0.5.x
tests/generated/flex/absolute_layout_justify_content_center.rs
Historia
Quién tocó qué
crudo
Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn absolute_layout_justify_content_center() {
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 position: taffy::style::Position::Absolute,
9 size: taffy::geometry::Size {
10 width: taffy::style::Dimension::Length(60f32),
11 height: taffy::style::Dimension::Length(40f32),
12 },
13 ..Default::default()
14 })
15 .unwrap();
16 let node = taffy
17 .new_with_children(
18 taffy::style::Style {
19 justify_content: Some(taffy::style::JustifyContent::Center),
20 size: taffy::geometry::Size {
21 width: taffy::style::Dimension::Length(110f32),
22 height: taffy::style::Dimension::Length(100f32),
23 },
24 ..Default::default()
25 },
26 &[node0],
27 )
28 .unwrap();
29 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
30 println!("\nComputed tree:");
31 taffy.print_tree(node);
32 println!();
33 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
34 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
35 assert_eq!(size.width, 110f32, "width of node {:?}. Expected {}. Actual {}", node, 110f32, size.width);
36 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
37 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
38 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
39 #[cfg(feature = "content_size")]
40 assert_eq!(
41 layout.scroll_width(),
42 0f32,
43 "scroll_width of node {:?}. Expected {}. Actual {}",
44 node,
45 0f32,
46 layout.scroll_width()
47 );
48 #[cfg(feature = "content_size")]
49 assert_eq!(
50 layout.scroll_height(),
51 0f32,
52 "scroll_height of node {:?}. Expected {}. Actual {}",
53 node,
54 0f32,
55 layout.scroll_height()
56 );
57 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
58 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
59 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node0, 60f32, size.width);
60 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
61 assert_eq!(location.x, 25f32, "x of node {:?}. Expected {}. Actual {}", node0, 25f32, location.x);
62 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
63 #[cfg(feature = "content_size")]
64 assert_eq!(
65 layout.scroll_width(),
66 0f32,
67 "scroll_width of node {:?}. Expected {}. Actual {}",
68 node0,
69 0f32,
70 layout.scroll_width()
71 );
72 #[cfg(feature = "content_size")]
73 assert_eq!(
74 layout.scroll_height(),
75 0f32,
76 "scroll_height of node {:?}. Expected {}. Actual {}",
77 node0,
78 0f32,
79 layout.scroll_height()
80 );
81}