⎇ float-layout
tests/generated/grid/grid_fit_content_percent_definite_max_content.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Use tagged pointer to represent size/length values (#769)
1#[test]
2#[allow(non_snake_case)]
3fn grid_fit_content_percent_definite_max_content__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_with_context(
9 taffy::style::Style { ..Default::default() },
10 crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
11 )
12 .unwrap();
13 let node = taffy
14 .new_with_children(
15 taffy::style::Style {
16 display: taffy::style::Display::Grid,
17 grid_template_rows: vec![length(40f32)],
18 grid_template_columns: vec![fit_content(percent(0.5f32))],
19 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(60f32), height: auto() },
20 ..Default::default()
21 },
22 &[node0],
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 let layout = taffy.layout(node).unwrap();
30 let Layout { size, location, .. } = layout;
31 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node, 60f32, size.width);
32 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, 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 let layout = taffy.layout(node0).unwrap();
36 let Layout { size, location, .. } = layout;
37 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
38 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
39 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
40 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
41}
42
43#[test]
44#[allow(non_snake_case)]
45fn grid_fit_content_percent_definite_max_content__content_box() {
46 #[allow(unused_imports)]
47 use taffy::{prelude::*, Layout};
48 let mut taffy = crate::new_test_tree();
49 let node0 = taffy
50 .new_leaf_with_context(
51 taffy::style::Style { box_sizing: taffy::style::BoxSizing::ContentBox, ..Default::default() },
52 crate::TestNodeContext::ahem_text("HH", crate::WritingMode::Horizontal),
53 )
54 .unwrap();
55 let node = taffy
56 .new_with_children(
57 taffy::style::Style {
58 display: taffy::style::Display::Grid,
59 box_sizing: taffy::style::BoxSizing::ContentBox,
60 grid_template_rows: vec![length(40f32)],
61 grid_template_columns: vec![fit_content(percent(0.5f32))],
62 size: taffy::geometry::Size { width: taffy::style::Dimension::from_length(60f32), height: auto() },
63 ..Default::default()
64 },
65 &[node0],
66 )
67 .unwrap();
68 taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
69 println!("\nComputed tree:");
70 taffy.print_tree(node);
71 println!();
72 let layout = taffy.layout(node).unwrap();
73 let Layout { size, location, .. } = layout;
74 assert_eq!(size.width, 60f32, "width of node {:?}. Expected {}. Actual {}", node, 60f32, size.width);
75 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node, 40f32, size.height);
76 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
77 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
78 let layout = taffy.layout(node0).unwrap();
79 let Layout { size, location, .. } = layout;
80 assert_eq!(size.width, 20f32, "width of node {:?}. Expected {}. Actual {}", node0, 20f32, size.width);
81 assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0, 40f32, size.height);
82 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
83 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
84}