⎇ 0.5.x
tests/generated/flex/min_max_percent_different_width_height.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn min_max_percent_different_width_height() {
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_with_context(
8 taffy::style::Style {
9 min_size: taffy::geometry::Size {
10 width: taffy::style::Dimension::Percent(0.1f32),
11 height: taffy::style::Dimension::Percent(0.1f32),
12 },
13 max_size: taffy::geometry::Size {
14 width: taffy::style::Dimension::Percent(0.1f32),
15 height: taffy::style::Dimension::Percent(0.1f32),
16 },
17 ..Default::default()
18 },
19 crate::TextMeasure { text_content: "", writing_mode: crate::WritingMode::Horizontal, _aspect_ratio: None },
20 )
21 .unwrap();
22 let node = taffy
23 .new_with_children(
24 taffy::style::Style {
25 flex_direction: taffy::style::FlexDirection::Column,
26 align_items: Some(taffy::style::AlignItems::FlexStart),
27 size: taffy::geometry::Size {
28 width: taffy::style::Dimension::Length(100f32),
29 height: taffy::style::Dimension::Length(200f32),
30 },
31 ..Default::default()
32 },
33 &[node0],
34 )
35 .unwrap();
36 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
37 println!("\nComputed tree:");
38 taffy.print_tree(node);
39 println!();
40 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
41 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
42 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
43 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node, 200f32, size.height);
44 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
45 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
46 #[cfg(feature = "content_size")]
47 assert_eq!(
48 layout.scroll_width(),
49 0f32,
50 "scroll_width of node {:?}. Expected {}. Actual {}",
51 node,
52 0f32,
53 layout.scroll_width()
54 );
55 #[cfg(feature = "content_size")]
56 assert_eq!(
57 layout.scroll_height(),
58 0f32,
59 "scroll_height of node {:?}. Expected {}. Actual {}",
60 node,
61 0f32,
62 layout.scroll_height()
63 );
64 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
65 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
66 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node0, 10f32, size.width);
67 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0, 20f32, size.height);
68 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
69 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
70 #[cfg(feature = "content_size")]
71 assert_eq!(
72 layout.scroll_width(),
73 0f32,
74 "scroll_width of node {:?}. Expected {}. Actual {}",
75 node0,
76 0f32,
77 layout.scroll_width()
78 );
79 #[cfg(feature = "content_size")]
80 assert_eq!(
81 layout.scroll_height(),
82 0f32,
83 "scroll_height of node {:?}. Expected {}. Actual {}",
84 node0,
85 0f32,
86 layout.scroll_height()
87 );
88}