⎇ 3bc35ec3b541eea8ea62344722f155ce9b22e227
tests/generated/leaf/leaf_with_content_and_padding.rs
History
Who touched what
raw
Implement `box-sizing: content-box` (#675)
1#[test]
2#[allow(non_snake_case)]
3fn leaf_with_content_and_padding__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, tree::Layout, TaffyTree};
6 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
7 let node = taffy
8 .new_leaf_with_context(
9 taffy::style::Style {
10 padding: taffy::geometry::Rect {
11 left: taffy::style::LengthPercentage::Length(8f32),
12 right: taffy::style::LengthPercentage::Length(4f32),
13 top: taffy::style::LengthPercentage::Length(2f32),
14 bottom: taffy::style::LengthPercentage::Length(6f32),
15 },
16 ..Default::default()
17 },
18 crate::TextMeasure {
19 text_content: "HHHH",
20 writing_mode: crate::WritingMode::Horizontal,
21 _aspect_ratio: None,
22 },
23 )
24 .unwrap();
25 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
26 println!("\nComputed tree:");
27 taffy.print_tree(node);
28 println!();
29 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
30 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
31 assert_eq!(size.width, 52f32, "width of node {:?}. Expected {}. Actual {}", node, 52f32, size.width);
32 assert_eq!(size.height, 18f32, "height of node {:?}. Expected {}. Actual {}", node, 18f32, size.height);
33 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
34 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
35 #[cfg(feature = "content_size")]
36 assert_eq!(
37 layout.scroll_width(),
38 0f32,
39 "scroll_width of node {:?}. Expected {}. Actual {}",
40 node,
41 0f32,
42 layout.scroll_width()
43 );
44 #[cfg(feature = "content_size")]
45 assert_eq!(
46 layout.scroll_height(),
47 0f32,
48 "scroll_height of node {:?}. Expected {}. Actual {}",
49 node,
50 0f32,
51 layout.scroll_height()
52 );
53}
54
55#[test]
56#[allow(non_snake_case)]
57fn leaf_with_content_and_padding__content_box() {
58 #[allow(unused_imports)]
59 use taffy::{prelude::*, tree::Layout, TaffyTree};
60 let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
61 let node = taffy
62 .new_leaf_with_context(
63 taffy::style::Style {
64 box_sizing: taffy::style::BoxSizing::ContentBox,
65 padding: taffy::geometry::Rect {
66 left: taffy::style::LengthPercentage::Length(8f32),
67 right: taffy::style::LengthPercentage::Length(4f32),
68 top: taffy::style::LengthPercentage::Length(2f32),
69 bottom: taffy::style::LengthPercentage::Length(6f32),
70 },
71 ..Default::default()
72 },
73 crate::TextMeasure {
74 text_content: "HHHH",
75 writing_mode: crate::WritingMode::Horizontal,
76 _aspect_ratio: None,
77 },
78 )
79 .unwrap();
80 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
81 println!("\nComputed tree:");
82 taffy.print_tree(node);
83 println!();
84 #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
85 let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
86 assert_eq!(size.width, 52f32, "width of node {:?}. Expected {}. Actual {}", node, 52f32, size.width);
87 assert_eq!(size.height, 18f32, "height of node {:?}. Expected {}. Actual {}", node, 18f32, size.height);
88 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
89 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
90 #[cfg(feature = "content_size")]
91 assert_eq!(
92 layout.scroll_width(),
93 0f32,
94 "scroll_width of node {:?}. Expected {}. Actual {}",
95 node,
96 0f32,
97 layout.scroll_width()
98 );
99 #[cfg(feature = "content_size")]
100 assert_eq!(
101 layout.scroll_height(),
102 0f32,
103 "scroll_height of node {:?}. Expected {}. Actual {}",
104 node,
105 0f32,
106 layout.scroll_height()
107 );
108}