matthunz / bevy-compose

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bevy-compose

Crates.io version docs.rs docs CI status

Reactive UI framework for Bevy.

This crate provides a framework for UI and other reactive systems using the ECS. Components can be created with lazy and run in parallel like regular systems (they can even use Local and other system parameters).

#[derive(Component, Deref, DerefMut)]
struct Count(i32);

fn app() -> impl Compose {
    lazy(|mut count: UseState<Count>| {
        let (count, count_entity) = count.use_state(|| Count(0));

        flex((
            format!("High five count: {}", **count),
            flex("Up high!").on_click(move |mut count_query: Query<&mut Count>| {
                if let Ok(mut count) = count_query.get_mut(count_entity) {
                    **count += 1
                }
            }),
            flex("Down low!").on_click(move |mut count_query: Query<&mut Count>| {
                if let Ok(mut count) = count_query.get_mut(count_entity) {
                    **count -= 1
                }
            }),
        ))
    })
}

Inspiration

This crate is inspired by Xilem, Concoct and SwiftUI with its typed approach to reactivity.

About

License:Apache License 2.0


Languages

Language:Rust 100.0%