1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use bevy::prelude::*;
use bevy_compose::{
    compose::{flex, memo},
    Compose, ComposePlugin,
};

#[derive(Resource)]
struct Count(i32);

fn ui(count: Res<Count>) -> impl Compose {
    memo(
        count.0,
        flex((
            format!("High five count: {}", count.0),
            flex("Up high!")
                .on_click(|mut count: ResMut<Count>| count.0 += 1)
                .on_hover(|| {
                    dbg!("Hover!");
                }),
            flex("Down low!").on_click(|mut count: ResMut<Count>| count.0 -= 1),
            if count.0 == 2 {
                Some("The number 2!")
            } else {
                None
            },
        )),
    )
}

fn main() {
    let mut app = App::new();

    app.world.insert_resource(Count(0));
    app.world
        .spawn((Camera2dBundle::default(), IsDefaultUiCamera));

    app.add_plugins((DefaultPlugins, ComposePlugin::new(ui)))
        .run();
}