⎇ float-layout
tests/generated/flex/measure_child_constraint_padding_parent.rs
Historia
Quién tocó qué
crudo
Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn measure_child_constraint_padding_parent__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node0 = taffy . new_leaf_with_context (taffy :: style :: Style { .. Default :: default () } , crate :: TestNodeContext :: ahem_text ("HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH" , crate :: WritingMode :: Horizontal) ,) . unwrap () ;
8 let node = taffy
9 .new_with_children(
10 taffy::style::Style {
11 size: taffy::geometry::Size {
12 width: taffy::style::Dimension::from_length(50f32),
13 height: taffy::style::Dimension::AUTO,
14 },
15 padding: taffy::geometry::Rect {
16 left: length(10f32),
17 right: length(10f32),
18 top: length(10f32),
19 bottom: length(10f32),
20 },
21 ..Default::default()
22 },
23 &[node0],
24 )
25 .unwrap();
26 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
27 println!("\nComputed tree:");
28 taffy.print_tree(node);
29 println!();
30 let layout = taffy.layout(node).unwrap();
31 let Layout { size, location, .. } = layout;
32 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node, 50f32, size.width);
33 assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
34 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
35 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
36 let layout = taffy.layout(node0).unwrap();
37 let Layout { size, location, .. } = layout;
38 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
39 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
40 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node0, 10f32, location.x);
41 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node0, 10f32, location.y);
42}
43
44#[test]
45#[allow(non_snake_case)]
46fn measure_child_constraint_padding_parent__content_box() {
47 #[allow(unused_imports)]
48 use taffy::{prelude::*, Layout};
49 let mut taffy = crate::new_test_tree();
50 let node0 = taffy . new_leaf_with_context (taffy :: style :: Style { box_sizing : taffy :: style :: BoxSizing :: ContentBox , .. Default :: default () } , crate :: TestNodeContext :: ahem_text ("HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH" , crate :: WritingMode :: Horizontal) ,) . unwrap () ;
51 let node = taffy
52 .new_with_children(
53 taffy::style::Style {
54 box_sizing: taffy::style::BoxSizing::ContentBox,
55 size: taffy::geometry::Size {
56 width: taffy::style::Dimension::from_length(50f32),
57 height: taffy::style::Dimension::AUTO,
58 },
59 padding: taffy::geometry::Rect {
60 left: length(10f32),
61 right: length(10f32),
62 top: length(10f32),
63 bottom: length(10f32),
64 },
65 ..Default::default()
66 },
67 &[node0],
68 )
69 .unwrap();
70 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
71 println!("\nComputed tree:");
72 taffy.print_tree(node);
73 println!();
74 let layout = taffy.layout(node).unwrap();
75 let Layout { size, location, .. } = layout;
76 assert_eq!(size.width, 70f32, "width of node {:?}. Expected {}. Actual {}", node, 70f32, size.width);
77 assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node, 120f32, size.height);
78 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
79 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
80 let layout = taffy.layout(node0).unwrap();
81 let Layout { size, location, .. } = layout;
82 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0, 100f32, size.width);
83 assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0, 100f32, size.height);
84 assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node0, 10f32, location.x);
85 assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node0, 10f32, location.y);
86}