⎇ float-layout
tests/generated/flex/measure_remeasure_child_after_shrinking.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_remeasure_child_after_shrinking__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node0 = taffy
8 .new_leaf(taffy::style::Style {
9 flex_shrink: 0f32,
10 size: taffy::geometry::Size {
11 width: taffy::style::Dimension::from_length(50f32),
12 height: taffy::style::Dimension::from_length(50f32),
13 },
14 ..Default::default()
15 })
16 .unwrap();
17 let node1 = taffy
18 .new_leaf_with_context(
19 taffy::style::Style { ..Default::default() },
20 crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
21 )
22 .unwrap();
23 let node = taffy
24 .new_with_children(
25 taffy::style::Style {
26 align_items: Some(taffy::style::AlignItems::Start),
27 size: taffy::geometry::Size {
28 width: taffy::style::Dimension::from_length(100f32),
29 height: taffy::style::Dimension::AUTO,
30 },
31 ..Default::default()
32 },
33 &[node0, node1],
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 let layout = taffy.layout(node).unwrap();
41 let Layout { size, location, .. } = layout;
42 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
43 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, 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 let layout = taffy.layout(node0).unwrap();
47 let Layout { size, location, .. } = layout;
48 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
49 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
50 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
51 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
52 let layout = taffy.layout(node1).unwrap();
53 let Layout { size, location, .. } = layout;
54 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
55 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
56 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
57 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
58}
59
60#[test]
61#[allow(non_snake_case)]
62fn measure_remeasure_child_after_shrinking__content_box() {
63 #[allow(unused_imports)]
64 use taffy::{prelude::*, Layout};
65 let mut taffy = crate::new_test_tree();
66 let node0 = taffy
67 .new_leaf(taffy::style::Style {
68 box_sizing: taffy::style::BoxSizing::ContentBox,
69 flex_shrink: 0f32,
70 size: taffy::geometry::Size {
71 width: taffy::style::Dimension::from_length(50f32),
72 height: taffy::style::Dimension::from_length(50f32),
73 },
74 ..Default::default()
75 })
76 .unwrap();
77 let node1 = taffy
78 .new_leaf_with_context(
79 taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
80 crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
81 )
82 .unwrap();
83 let node = taffy
84 .new_with_children(
85 taffy::style::Style {
86 box_sizing: taffy::style::BoxSizing::ContentBox,
87 align_items: Some(taffy::style::AlignItems::Start),
88 size: taffy::geometry::Size {
89 width: taffy::style::Dimension::from_length(100f32),
90 height: taffy::style::Dimension::AUTO,
91 },
92 ..Default::default()
93 },
94 &[node0, node1],
95 )
96 .unwrap();
97 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
98 println!("\nComputed tree:");
99 taffy.print_tree(node);
100 println!();
101 let layout = taffy.layout(node).unwrap();
102 let Layout { size, location, .. } = layout;
103 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node, 100f32, size.width);
104 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
105 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
106 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
107 let layout = taffy.layout(node0).unwrap();
108 let Layout { size, location, .. } = layout;
109 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0, 50f32, size.width);
110 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0, 50f32, size.height);
111 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
112 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
113 let layout = taffy.layout(node1).unwrap();
114 let Layout { size, location, .. } = layout;
115 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node1, 20f32, size.width);
116 assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node1, 10f32, size.height);
117 assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node1, 50f32, location.x);
118 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
119}