gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1111HTML 1039Markdown 12TOML 94524 Definiciones

⎇ devin/1784875552-bfc-beside-floats examples/basic.rs Rust · 34 líneas · 1.1 KB Historia Quién tocó qué crudo

Use SCREAMING_SNAKE_CASE for alignment constants (#961) 9c58cc5d5 · Nico Burns ·

1use taffy::prelude::*;
2
3fn main() -> Result<(), taffy::TaffyError> {
4    let mut taffy: TaffyTree<()> = TaffyTree::new();
5
6    let child = taffy.new_leaf(Style {
7        size: Size { width: Dimension::from_percent(0.5), height: Dimension::AUTO },
8        ..Default::default()
9    })?;
10
11    let node = taffy.new_with_children(
12        Style {
13            size: Size { width: Dimension::from_length(100.0), height: Dimension::from_length(100.0) },
14            justify_content: Some(JustifyContent::CENTER),
15            ..Default::default()
16        },
17        &[child],
18    )?;
19
20    println!("Compute layout with 100x100 viewport:");
21    taffy.compute_layout(
22        node,
23        Size { height: AvailableSpace::Definite(100.0), width: AvailableSpace::Definite(100.0) },
24    )?;
25    println!("node: {:#?}", taffy.layout(node)?);
26    println!("child: {:#?}", taffy.layout(child)?);
27
28    println!("Compute layout with undefined (infinite) viewport:");
29    taffy.compute_layout(node, Size::MAX_CONTENT)?;
30    println!("node: {:#?}", taffy.layout(node)?);
31    println!("child: {:#?}", taffy.layout(child)?);
32
33    Ok(())
34}