Skip to content

matthunz/bevy-compose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

No description, website, or topics provided.

Resources

License

Apache-2.0, Unknown licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
Unknown
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages