Taffy layout algorithms backed by Bevy ECS.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-12-02 15:00:04 +08:00
benches Initial commit 2026-11-28 22:50:01 +08:00
examples Initial commit 2026-11-28 22:50:01 +08:00
src Initial commit 2026-11-28 22:50:01 +08:00
tests Initial commit 2026-11-28 22:50:01 +08:00
.gitignore Initial commit 2026-11-28 22:50:01 +08:00
AGENTS.md Initial commit 2026-11-28 22:50:01 +08:00
Cargo.lock Publish crate 2026-12-02 15:00:04 +08:00
Cargo.toml Publish crate 2026-12-02 15:00:04 +08:00
CONTRIBUTING.md Initial commit 2026-11-28 22:50:01 +08:00
LICENSE-APACHE Initial commit 2026-11-28 22:54:00 +08:00
LICENSE-MIT Initial commit 2026-11-28 22:50:01 +08:00
README.md Initial commit 2026-11-28 22:50:01 +08:00

bevy_taffy

Taffy layout algorithms backed by Bevy ECS. Supports Flexbox, Grid, and Block layout through SystemParam-based low-level traits and a TaffyTree high-level API. Nodes are entities with dedicated layout relationships; results use native Taffy types.

Example

Create nodes with Commands, then compute and read layouts inside ordinary systems. Apply creation commands before computing layout.

use bevy_ecs::{
    entity::Entity,
    query::{With, Without},
    schedule::Schedule,
    system::{Commands, ParamSet, Query},
    world::World,
};
use bevy_taffy::{
    LayoutMode, TaffyChildOf, TaffyLayout, TaffyNode, TaffyRead, TaffyTree,
    taffy::{Size, Style, prelude::{TaffyMaxContent, length}},
};

fn setup(mut commands: Commands) {
    let child = TaffyTree::new_leaf(&mut commands, Style {
        size: Size { width: length(80.0), height: length(24.0) },
        ..Default::default()
    });
    TaffyTree::new_with_children(
        &mut commands, Style::default(), &[child],
    );
}

fn layout(
    roots: Query<Entity, (With<TaffyNode>, Without<TaffyChildOf>)>,
    mut access: ParamSet<(TaffyLayout, TaffyRead)>,
) -> bevy_ecs::error::Result {
    for entity in &roots {
        let root = TaffyTree::new(&access.p1(), entity)?;
        root.compute_layout(
            &mut access.p0(), Size::MAX_CONTENT, LayoutMode::Unrounded,
        )?;
        let read = access.p1();
        let result = root.layout(&read, LayoutMode::Unrounded).unwrap();
        println!("Size: {:?}", result.size);
    }
    Ok(())
}

fn main() {
    let mut world = World::new();
    let mut startup = Schedule::default();
    startup.add_systems(setup);
    startup.run(&mut world);

    let mut update = Schedule::default();
    update.add_systems(layout);
    update.run(&mut world);
}

See examples/layout.rs for style updates, measurement, and rounding.