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