From b9dc61dad1c171fc040845b2799172926a318f8f Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Fri, 4 Aug 2023 21:39:04 -0700 Subject: [PATCH] audio inspector is pretty good actually --- bin/audio-inspect.rs | 104 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 84 insertions(+), 20 deletions(-) diff --git a/bin/audio-inspect.rs b/bin/audio-inspect.rs index 26abbde..c2e0590 100644 --- a/bin/audio-inspect.rs +++ b/bin/audio-inspect.rs @@ -16,7 +16,7 @@ fn main() { )) .add_systems(PreStartup, (load,)) .add_systems(Startup, (init,)) - .add_systems(Update, (save, update)) + .add_systems(Update, (save, update, sort_buttons)) .run() } @@ -41,24 +41,22 @@ fn load(server: Res) { fn init(mut commands: Commands) { commands.spawn(Camera3dBundle { ..default() }); - commands - .spawn(( - NodeBundle { - style: Style { - width: Val::Percent(100.0), - height: Val::Percent(100.0), - align_items: AlignItems::FlexStart, - flex_direction: FlexDirection::Column, - ..default() - }, - background_color: BackgroundColor(Color::MIDNIGHT_BLUE), + commands.spawn(( + NodeBundle { + style: Style { + width: Val::Percent(100.0), + height: Val::Percent(100.0), + align_items: AlignItems::FlexStart, + align_content: AlignContent::FlexStart, + flex_direction: FlexDirection::Row, + flex_wrap: FlexWrap::Wrap, ..default() }, - Container, - )) - .with_children(|parent| { - // Something might go here... - }); + background_color: BackgroundColor(Color::MIDNIGHT_BLUE), + ..default() + }, + Container, + )); } /// @@ -89,11 +87,25 @@ fn save( commands .spawn(( + Name::new(format!("{}", title)), ButtonBundle { - style: Style { ..default() }, + style: Style { + border: UiRect::all(Val::Px(1.0)), + margin: UiRect::all(Val::Px(2.0)), + padding: UiRect::all(Val::Px(2.0)), + ..default() + }, + border_color: BorderColor(Color::BLACK), ..default() }, - AudioItem(handle.clone()), + AudioBundle { + source: handle.clone(), + settings: PlaybackSettings { + mode: bevy::audio::PlaybackMode::Loop, + paused: true, + ..default() + }, + }, )) .with_children(|parent| { parent.spawn(TextBundle::from_section(title, style)); @@ -110,5 +122,57 @@ fn save( } } +fn sort_buttons( + mut container: Query<&mut Children, (With, Changed)>, + names: Query<&Name, With>, +) { + container.iter_mut().for_each(|mut children| { + children.sort_by(|&a, &b| { + names + .get(a) + .expect("Button has name") + .cmp(names.get(b).expect("Button has name")) + }); + }); +} + /// Update loop; play/pause/volume -fn update() {} +fn update( + mut interactions: Query< + (&Interaction, &AudioSink, &mut BackgroundColor), + (With