1use taffy::prelude::*;
2
3fn main() -> Result<(), taffy::TaffyError> {
4 let mut taffy: TaffyTree<()> = TaffyTree::new();
5
6 let child_t1 = taffy.new_leaf(Style {
8 size: Size { width: Dimension::from_length(5.0), height: Dimension::from_length(5.0) },
9 ..Default::default()
10 })?;
11
12 let div1 = taffy.new_with_children(
13 Style {
14 size: Size { width: Dimension::from_percent(0.5), height: Dimension::from_percent(1.0) },
15 ..Default::default()
17 },
18 &[child_t1],
19 )?;
20
21 let child_t2 = taffy.new_leaf(Style {
23 size: Size { width: Dimension::from_length(5.0), height: Dimension::from_length(5.0) },
24 ..Default::default()
25 })?;
26
27 let div2 = taffy.new_with_children(
28 Style {
29 size: Size { width: Dimension::from_percent(0.5), height: Dimension::from_percent(1.0) },
30 ..Default::default()
32 },
33 &[child_t2],
34 )?;
35
36 let container = taffy.new_with_children(
37 Style {
38 size: Size { width: Dimension::from_percent(1.0), height: Dimension::from_percent(1.0) },
39 ..Default::default()
40 },
41 &[div1, div2],
42 )?;
43
44 taffy.compute_layout(
45 container,
46 Size { height: AvailableSpace::Definite(100.0), width: AvailableSpace::Definite(100.0) },
47 )?;
48
49 println!("node: {:#?}", taffy.layout(container)?);
50
51 println!("div1: {:#?}", taffy.layout(div1)?);
52 println!("div2: {:#?}", taffy.layout(div2)?);
53
54 println!("child1: {:#?}", taffy.layout(child_t1)?);
55 println!("child2: {:#?}", taffy.layout(child_t2)?);
56
57 Ok(())
58}