tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81412 Definitions

⎇ c2db86dfc600067c6f4d70c8ea398cbcc5d42dbd examples/flexbox_gap.rs Rust · 24 lines · 832 B History Who touched what raw

Implement CSS Grid (#205) 6fd2c6bcb · Nico Burns ·

1use taffy::prelude::*;
2
3// Creates three 20px x 20px children, evenly spaced 10px apart from each other
4// Thus the container is 80px x 20px.
5
6fn main() -> Result<(), taffy::error::TaffyError> {
7    let mut taffy = Taffy::new();
8
9    let child_style = Style { size: Size { width: points(20.0), height: points(20.0) }, ..Default::default() };
10    let child0 = taffy.new_leaf(child_style.clone())?;
11    let child1 = taffy.new_leaf(child_style.clone())?;
12    let child2 = taffy.new_leaf(child_style.clone())?;
13
14    let root = taffy.new_with_children(
15        Style { gap: Size { width: points(10.0), height: zero() }, ..Default::default() },
16        &[child0, child1, child2],
17    )?;
18
19    // Compute layout and print result
20    taffy.compute_layout(root, Size::MAX_CONTENT)?;
21    taffy::debug::print_tree(&taffy, root);
22
23    Ok(())
24}