⎇ float-layout
tests/generated/blockflex/blockflex_block_in_flex_column.rs
Historia
Quién tocó qué
crudo
Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn blockflex_block_in_flex_column__border_box() {
4 #[allow(unused_imports)]
5 use taffy::{prelude::*, Layout};
6 let mut taffy = crate::new_test_tree();
7 let node0 =
8 taffy.new_leaf(taffy::style::Style { display: taffy::style::Display::Block, ..Default::default() }).unwrap();
9 let node1 = taffy
10 .new_leaf(taffy::style::Style {
11 display: taffy::style::Display::Block,
12 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
13 ..Default::default()
14 })
15 .unwrap();
16 let node = taffy
17 .new_with_children(
18 taffy::style::Style {
19 display: taffy::style::Display::Flex,
20 flex_direction: taffy::style::FlexDirection::Column,
21 size: taffy::geometry::Size {
22 width: taffy::style::Dimension::from_length(200f32),
23 height: taffy::style::Dimension::from_length(50f32),
24 },
25 ..Default::default()
26 },
27 &[node0, node1],
28 )
29 .unwrap();
30 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
31 println!("\nComputed tree:");
32 taffy.print_tree(node);
33 println!();
34 let layout = taffy.layout(node).unwrap();
35 let Layout { size, location, .. } = layout;
36 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
37 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
38 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
39 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
40 let layout = taffy.layout(node0).unwrap();
41 let Layout { size, location, .. } = layout;
42 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
43 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node0, 0f32, size.height);
44 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
45 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
46 let layout = taffy.layout(node1).unwrap();
47 let Layout { size, location, .. } = layout;
48 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
49 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node1, 0f32, size.height);
50 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
51 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
52}
53
54#[test]
55#[allow(non_snake_case)]
56fn blockflex_block_in_flex_column__content_box() {
57 #[allow(unused_imports)]
58 use taffy::{prelude::*, Layout};
59 let mut taffy = crate::new_test_tree();
60 let node0 = taffy
61 .new_leaf(taffy::style::Style {
62 display: taffy::style::Display::Block,
63 box_sizing: taffy::style::BoxSizing::ContentBox,
64 ..Default::default()
65 })
66 .unwrap();
67 let node1 = taffy
68 .new_leaf(taffy::style::Style {
69 display: taffy::style::Display::Block,
70 box_sizing: taffy::style::BoxSizing::ContentBox,
71 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(50f32), height: auto() },
72 ..Default::default()
73 })
74 .unwrap();
75 let node = taffy
76 .new_with_children(
77 taffy::style::Style {
78 display: taffy::style::Display::Flex,
79 box_sizing: taffy::style::BoxSizing::ContentBox,
80 flex_direction: taffy::style::FlexDirection::Column,
81 size: taffy::geometry::Size {
82 width: taffy::style::Dimension::from_length(200f32),
83 height: taffy::style::Dimension::from_length(50f32),
84 },
85 ..Default::default()
86 },
87 &[node0, node1],
88 )
89 .unwrap();
90 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
91 println!("\nComputed tree:");
92 taffy.print_tree(node);
93 println!();
94 let layout = taffy.layout(node).unwrap();
95 let Layout { size, location, .. } = layout;
96 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node, 200f32, size.width);
97 assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node, 50f32, size.height);
98 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
99 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
100 let layout = taffy.layout(node0).unwrap();
101 let Layout { size, location, .. } = layout;
102 assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0, 200f32, size.width);
103 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node0, 0f32, size.height);
104 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
105 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
106 let layout = taffy.layout(node1).unwrap();
107 let Layout { size, location, .. } = layout;
108 assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1, 50f32, size.width);
109 assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node1, 0f32, size.height);
110 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1, 0f32, location.x);
111 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1, 0f32, location.y);
112}