lazy/
lazy.rs

1use bevy::prelude::*;
2use bevy_compose::{compose, flex, handler_system, lazy, Compose, Composer};
3
4#[derive(Resource)]
5struct Count(i32);
6
7fn ui() -> impl Compose {
8    lazy(|count: Res<Count>| {
9        (
10            format!("High five count: {}", count.0),
11            flex("Up high!").on_click(|mut count: ResMut<Count>| count.0 += 1),
12            flex("Down low!").on_click(|mut count: ResMut<Count>| count.0 -= 1),
13        )
14    })
15}
16
17fn main() {
18    let mut app = App::new();
19
20    app.world.insert_resource(Count(0));
21    app.world.spawn(Composer::new(ui));
22    app.world
23        .spawn((Camera2dBundle::default(), IsDefaultUiCamera));
24
25    app.add_plugins(DefaultPlugins)
26        .add_systems(Update, (compose, handler_system))
27        .run();
28}