tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1061HTML 997Markdown 12TOML 83120 Definitions

⎇ cd73db35cfa2b31555a796e7972cd97a45554e17 tests/generated/flex/blitz_issue_88.rs Rust · 148 lines · 5.9 KB History Who touched what raw

Fix computation of intrinsic main size when it depends on a child's known cross size (#673) cd73db35c · Nico Burns ·

1#[test]
2fn blitz_issue_88() {
3    #[allow(unused_imports)]
4    use taffy::{prelude::*, tree::Layout, TaffyTree};
5    let mut taffy: TaffyTree<crate::TextMeasure> = TaffyTree::new();
6    let node000 = taffy
7        .new_leaf_with_context(
8            taffy::style::Style {
9                display: taffy::style::Display::Block,
10                flex_grow: 1f32,
11                flex_basis: taffy::style::Dimension::Length(0f32),
12                ..Default::default()
13            },
14            crate::TextMeasure {
15                text_content: "HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH",
16                writing_mode: crate::WritingMode::Horizontal,
17                _aspect_ratio: None,
18            },
19        )
20        .unwrap();
21    let node00 = taffy
22        .new_with_children(
23            taffy::style::Style { display: taffy::style::Display::Flex, flex_grow: 1f32, ..Default::default() },
24            &[node000],
25        )
26        .unwrap();
27    let node0 = taffy
28        .new_with_children(
29            taffy::style::Style {
30                display: taffy::style::Display::Flex,
31                flex_direction: taffy::style::FlexDirection::Column,
32                justify_content: Some(taffy::style::JustifyContent::Start),
33                ..Default::default()
34            },
35            &[node00],
36        )
37        .unwrap();
38    let node = taffy
39        .new_with_children(
40            taffy::style::Style {
41                display: taffy::style::Display::Block,
42                size: taffy::geometry::Size { width: taffy::style::Dimension::Length(600f32), height: auto() },
43                ..Default::default()
44            },
45            &[node0],
46        )
47        .unwrap();
48    taffy.compute_layout_with_measure(node, taffy::geometry::Size::MAX_CONTENT, crate::test_measure_function).unwrap();
49    println!("\nComputed tree:");
50    taffy.print_tree(node);
51    println!();
52    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
53    let layout @ Layout { size, location, .. } = taffy.layout(node).unwrap();
54    assert_eq!(size.width, 600f32, "width of node {:?}. Expected {}. Actual {}", node, 600f32, size.width);
55    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node, 10f32, size.height);
56    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node, 0f32, location.x);
57    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node, 0f32, location.y);
58    #[cfg(feature = "content_size")]
59    assert_eq!(
60        layout.scroll_width(),
61        0f32,
62        "scroll_width of node {:?}. Expected {}. Actual {}",
63        node,
64        0f32,
65        layout.scroll_width()
66    );
67    #[cfg(feature = "content_size")]
68    assert_eq!(
69        layout.scroll_height(),
70        0f32,
71        "scroll_height of node {:?}. Expected {}. Actual {}",
72        node,
73        0f32,
74        layout.scroll_height()
75    );
76    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
77    let layout @ Layout { size, location, .. } = taffy.layout(node0).unwrap();
78    assert_eq!(size.width, 600f32, "width of node {:?}. Expected {}. Actual {}", node0, 600f32, size.width);
79    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0, 10f32, size.height);
80    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0, 0f32, location.x);
81    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0, 0f32, location.y);
82    #[cfg(feature = "content_size")]
83    assert_eq!(
84        layout.scroll_width(),
85        0f32,
86        "scroll_width of node {:?}. Expected {}. Actual {}",
87        node0,
88        0f32,
89        layout.scroll_width()
90    );
91    #[cfg(feature = "content_size")]
92    assert_eq!(
93        layout.scroll_height(),
94        0f32,
95        "scroll_height of node {:?}. Expected {}. Actual {}",
96        node0,
97        0f32,
98        layout.scroll_height()
99    );
100    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
101    let layout @ Layout { size, location, .. } = taffy.layout(node00).unwrap();
102    assert_eq!(size.width, 600f32, "width of node {:?}. Expected {}. Actual {}", node00, 600f32, size.width);
103    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node00, 10f32, size.height);
104    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node00, 0f32, location.x);
105    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node00, 0f32, location.y);
106    #[cfg(feature = "content_size")]
107    assert_eq!(
108        layout.scroll_width(),
109        0f32,
110        "scroll_width of node {:?}. Expected {}. Actual {}",
111        node00,
112        0f32,
113        layout.scroll_width()
114    );
115    #[cfg(feature = "content_size")]
116    assert_eq!(
117        layout.scroll_height(),
118        0f32,
119        "scroll_height of node {:?}. Expected {}. Actual {}",
120        node00,
121        0f32,
122        layout.scroll_height()
123    );
124    #[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
125    let layout @ Layout { size, location, .. } = taffy.layout(node000).unwrap();
126    assert_eq!(size.width, 600f32, "width of node {:?}. Expected {}. Actual {}", node000, 600f32, size.width);
127    assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node000, 10f32, size.height);
128    assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node000, 0f32, location.x);
129    assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node000, 0f32, location.y);
130    #[cfg(feature = "content_size")]
131    assert_eq!(
132        layout.scroll_width(),
133        0f32,
134        "scroll_width of node {:?}. Expected {}. Actual {}",
135        node000,
136        0f32,
137        layout.scroll_width()
138    );
139    #[cfg(feature = "content_size")]
140    assert_eq!(
141        layout.scroll_height(),
142        0f32,
143        "scroll_height of node {:?}. Expected {}. Actual {}",
144        node000,
145        0f32,
146        layout.scroll_height()
147    );
148}