⎇ 0.3.x
tests/generated/min_max_percent_different_width_height.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Reinstate FlexStart and FlexEnd alignment variants (#336)
1#[test]
2fn min_max_percent_different_width_height() {
3 use slotmap::Key;
4 #[allow(unused_imports)]
5 use taffy::{layout::Layout, prelude::*};
6 let mut taffy = taffy::Taffy::new();
7 let node0 = taffy
8 .new_leaf_with_measure(
9 taffy::style::Style {
10 min_size: taffy::geometry::Size {
11 width: taffy::style::Dimension::Percent(0.1f32),
12 height: taffy::style::Dimension::Percent(0.1f32),
13 },
14 max_size: taffy::geometry::Size {
15 width: taffy::style::Dimension::Percent(0.1f32),
16 height: taffy::style::Dimension::Percent(0.1f32),
17 },
18 ..Default::default()
19 },
20 taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| {
21 const TEXT: &str = "\n ";
22 super::measure_standard_text(
23 known_dimensions,
24 available_space,
25 TEXT,
26 super::WritingMode::Horizontal,
27 None,
28 )
29 }),
30 )
31 .unwrap();
32 let node = taffy
33 .new_with_children(
34 taffy::style::Style {
35 flex_direction: taffy::style::FlexDirection::Column,
36 align_items: Some(taffy::style::AlignItems::FlexStart),
37 size: taffy::geometry::Size {
38 width: taffy::style::Dimension::Points(100f32),
39 height: taffy::style::Dimension::Points(200f32),
40 },
41 ..Default::default()
42 },
43 &[node0],
44 )
45 .unwrap();
46 taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap();
47 println!("\nComputed tree:");
48 taffy::debug::print_tree(&taffy, node);
49 println!();
50 let Layout { size, location, .. } = taffy.layout(node).unwrap();
51 assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width);
52 assert_eq!(size.height, 200f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 200f32, size.height);
53 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x);
54 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y);
55 let Layout { size, location, .. } = taffy.layout(node0).unwrap();
56 assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, size.width);
57 assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height);
58 assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x);
59 assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y);
60}