use std::fmt::Debug; use bevy::prelude::*; use mevy::*; pub fn main() { let mut app = App::new(); app.add_plugins(DefaultPlugins) .add_systems(Startup,startup); app.run(); } fn startup(mut world:Commands){ entity!{Camera2d} entity!{ BackgroundColor(#ff0000); BorderColor::all(#00ffff); Node{ width:80px, height:80px, margin:[>16px], !}; .observe(destroy_on::(e1)); .observe(destroy_on::(named_child)); [ // auto-called 'e1' Node{ width:20%, height:20%, !}; BackgroundColor(#00ff00); ] [ Node{ width:20%, height:20%, !}; BackgroundColor(#00aaff); .observe(destroy_self_on::); ] [named_child][ Node{ width:20%, height:20%, !}; BackgroundColor(#00ffaa); Visibility!; ] } } fn destroy_on (entity:Entity) -> impl Fn(On>,Commands) { move|_,mut world|{if let Ok(mut ecmd) = world.get_entity(entity){ ecmd.despawn(); }} } fn destroy_self_on (trigger:On>,mut cmd:Commands) { cmd.entity(trigger.observer()).despawn(); }