use bevy::prelude::*;
use pecs::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(PecsPlugin)
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.promise(|| ()).then_repeat(asyn!(
buttons: Query<&Name, Changed<Interaction>>
=> {
if buttons.is_empty() {
info!("No changes");
} else {
info!("Changed buttons:");
for name in buttons.iter() {
info!(" {name}");
}
}
asyn::timeout(1.).with_result(Repeat::forever())
}));
commands
.spawn(NodeBundle {
style: Style {
width: Val::Percent(100.),
height: Val::Percent(100.),
justify_content: JustifyContent::SpaceAround,
align_content: AlignContent::SpaceAround,
flex_direction: FlexDirection::Column,
..default()
},
..default()
})
.with_children(|parent| {
for y in 0..4 {
parent
.spawn(NodeBundle {
style: Style {
width: Val::Percent(100.),
height: Val::Percent(20.),
flex_direction: FlexDirection::Row,
justify_content: JustifyContent::SpaceAround,
..default()
},
..default()
})
.with_children(|parent| {
for x in 0..4 {
parent
.spawn(ButtonBundle {
background_color: Color::rgb(0.8, 0.8, 0.8).into(),
style: Style {
width: Val::Percent(20.),
height: Val::Percent(100.),
..default()
},
..default()
})
.insert(Name::new(format!("{x}x{y}")));
}
});
}
});
}