use bevy::dev_tools::ui_debug_overlay::UiDebugOptions; use bevy::prelude::*; use bevy_color::palettes::tailwind; use bevy_progressbar::ProgressBar; use bevy_progressbar::ProgressBarBundle; use bevy_progressbar::ProgressBarMaterial; use bevy_utils::{default, Duration}; #[derive(Component)] struct ExampleProgress; #[derive(Component)] struct ExampleUpdateSections(pub Timer); fn main() { App::new() .add_plugins((DefaultPlugins, bevy_progressbar::ProgressBarPlugin)) .add_plugins(bevy::dev_tools::ui_debug_overlay::DebugUiPlugin) .add_systems(Startup, (setup,)) .add_systems(Update, (increase_progress, update_sections, close_on_esc)) .run(); } fn setup( mut commands: Commands, mut materials: ResMut>, mut options: ResMut, ) { options.enabled = true; commands.spawn(Camera2dBundle::default()); commands .spawn(NodeBundle { style: Style { position_type: PositionType::Absolute, display: Display::Grid, padding: UiRect::all(Val::Px(36.0)), row_gap: Val::Px(12.0), width: Val::Percent(100.0), height: Val::Percent(100.0), ..default() }, ..default() }) .with_children(|wrapper| { for (index, bar) in [ ProgressBar::new(vec![ (200, tailwind::RED_500.into()), (400, tailwind::BLUE_500.into()), ]), ProgressBar::new(vec![ (200, tailwind::RED_500.into()), (400, tailwind::BLUE_500.into()), (300, tailwind::GREEN_500.into()), ]) .set_progress(1.0) .clone(), ProgressBar::new(vec![(200, tailwind::RED_500.into())]) .set_progress(1.0) .clone(), ] .into_iter() .enumerate() { let mut entity_command = wrapper.spawn(ProgressBarBundle::new(bar, &mut materials)); if index == 0 { entity_command.insert(ExampleProgress); } if index == 2 { entity_command.insert(ExampleUpdateSections(Timer::new( Duration::from_secs(2), TimerMode::Repeating, ))); } } }); } fn increase_progress(mut query: Query<&mut ProgressBar, With>) { for mut bar in query.iter_mut() { if bar.is_finished() { bar.reset(); } else { bar.increase_progress(0.01); } } } fn update_sections( mut query: Query<(&mut ProgressBar, &mut ExampleUpdateSections)>, time: Res