tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 707HTML 660Markdown 12TOML 62344 Definitions

⎇ df1ba340c0b72fb4dfcf1b5005adaa343f0a0003 tests/rounding.rs Rust · 30 lines · 1.0 KB History Who touched what raw

Add `taffy_test_helpers` crate (#755) 2a3e8476b · Nico Burns ·

1use taffy::prelude::*;
2use taffy_test_helpers::new_test_tree;
3
4#[test]
5fn rounding_doesnt_leave_gaps() {
6    // First create an instance of TaffyTree
7    let mut taffy = new_test_tree();
8
9    let w_square = Size { width: length(100.3), height: length(100.3) };
10    let child_a = taffy.new_leaf(Style { size: w_square, ..Default::default() }).unwrap();
11    let child_b = taffy.new_leaf(Style { size: w_square, ..Default::default() }).unwrap();
12
13    let root_node = taffy
14        .new_with_children(
15            Style {
16                size: Size { width: length(963.3333), height: length(1000.) },
17                justify_content: Some(JustifyContent::Center),
18                ..Default::default()
19            },
20            &[child_a, child_b],
21        )
22        .unwrap();
23
24    taffy.compute_layout(root_node, Size::MAX_CONTENT).unwrap();
25    taffy.print_tree(root_node);
26
27    let layout_a = taffy.layout(child_a).unwrap();
28    let layout_b = taffy.layout(child_b).unwrap();
29    assert_eq!(layout_a.location.x + layout_a.size.width, layout_b.location.x);
30}