⎇ 04e20d1de5cd584bf0760071cf130dd55f5b0089
tests/generated/flex/content_size.rs
Historia
Quién tocó qué
crudo
Rename Taffy struct to TaffyTree (#580)
1#[test]
2fn content_size() {
3 #[allow(unused_imports)]
4 use taffy::{prelude::*, tree::Layout, TaffyTree};
5 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6 let node00 = taffy
7 .new_leaf_with_context(
8 taffy::style::Style {
9 position: taffy::style::Position::Absolute,
10 flex_shrink: 0f32,
11 size: taffy::geometry::Size {
12 width: taffy::style::Dimension::Percent(1f32),
13 height: taffy::style::Dimension::Length(20f32),
14 },
15 inset: taffy::geometry::Rect {
16 left: auto(),
17 right: auto(),
18 top: taffy::style::LengthPercentageAuto::Length(-10f32),
19 bottom: auto(),
20 },
21 ..Default::default()
22 },
23 crate::TextMeasure {
24 text_content: "HHHH\u{200b}HHHH",
25 writing_mode: crate::WritingMode::Horizontal,
26 _aspect_ratio: None,
27 },
28 )
29 .unwrap();
30 let node0 = taffy
31 .new_with_children(
32 taffy::style::Style {
33 size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Length(30f32) },
34 ..Default::default()
35 },
36 &[node00],
37 )
38 .unwrap();
39 let node = taffy
40 .new_with_children(
41 taffy::style::Style {
42 display: taffy::style::Display::Flex,
43 flex_direction: taffy::style::FlexDirection::Column,
44 overflow: taffy::geometry::Point {
45 x: taffy::style::Overflow::Visible,
46 y: taffy::style::Overflow::Scroll,
47 },
48 scrollbar_width: 15f32,
49 size: taffy::geometry::Size {
50 width: taffy::style::Dimension::Length(100f32),
51 height: taffy::style::Dimension::Length(100f32),
52 },
53 ..Default::default()
54 },
55 &[node0],
56 )
57 .unwrap();
58 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
59 println!("\nComputed tree:");
60 taffy.print_tree(node);
61 println!();
62 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
63 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
64 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
65 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node, 100f32, size.height);
66 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
67 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
68 #[cfg(feature = "content_size")]
69 assert_eq!(
70 layout.scroll_width(),
71 0f32,
72 "scroll_width of node {:?}. Expected {}. Actual {}",
73 node,
74 0f32,
75 layout.scroll_width()
76 );
77 #[cfg(feature = "content_size")]
78 assert_eq!(
79 layout.scroll_height(),
80 0f32,
81 "scroll_height of node {:?}. Expected {}. Actual {}",
82 node,
83 0f32,
84 layout.scroll_height()
85 );
86 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
87 let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
88 assert_eq!(size.width, 85f32, "width of node {:?}. Expected {}. Actual {}", node0, 85f32, size.width);
89 assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node0, 30f32, size.height);
90 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
91 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
92 #[cfg(feature = "content_size")]
93 assert_eq!(
94 layout.scroll_width(),
95 0f32,
96 "scroll_width of node {:?}. Expected {}. Actual {}",
97 node0,
98 0f32,
99 layout.scroll_width()
100 );
101 #[cfg(feature = "content_size")]
102 assert_eq!(
103 layout.scroll_height(),
104 0f32,
105 "scroll_height of node {:?}. Expected {}. Actual {}",
106 node0,
107 0f32,
108 layout.scroll_height()
109 );
110 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
111 let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
112 assert_eq!(size.width, 85f32, "width of node {:?}. Expected {}. Actual {}", node00, 85f32, size.width);
113 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node00, 20f32, size.height);
114 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
115 assert_eq!(location.y, -10f32, "y of node {:?}. Expected {}. Actual {}", node00, -10f32, location.y);
116 #[cfg(feature = "content_size")]
117 assert_eq!(
118 layout.scroll_width(),
119 0f32,
120 "scroll_width of node {:?}. Expected {}. Actual {}",
121 node00,
122 0f32,
123 layout.scroll_width()
124 );
125 #[cfg(feature = "content_size")]
126 assert_eq!(
127 layout.scroll_height(),
128 0f32,
129 "scroll_height of node {:?}. Expected {}. Actual {}",
130 node00,
131 0f32,
132 layout.scroll_height()
133 );
134}