mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 06:21:23 +00:00
new feature: now can play file without opening any dir
This commit is contained in:
+13
-9
@@ -1,7 +1,7 @@
|
||||
use crate::gui::SoundpadGui;
|
||||
use crate::gui::{SUPPORTED_EXTENSIONS, SoundpadGui};
|
||||
use egui::{
|
||||
AtomExt, Button, Color32, ComboBox, FontFamily, Label, RichText, ScrollArea, Slider, TextEdit,
|
||||
Ui, Vec2,
|
||||
Align, AtomExt, Button, Color32, ComboBox, FontFamily, Label, Layout, RichText, ScrollArea,
|
||||
Slider, TextEdit, Ui, Vec2,
|
||||
};
|
||||
use egui_material_icons::icons;
|
||||
use pwsp::types::audio_player::PlayerState;
|
||||
@@ -216,21 +216,25 @@ impl SoundpadGui {
|
||||
}
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
let add_dir_button = egui::Button::new(icons::ICON_ADD).frame(false);
|
||||
let add_dir_button = Button::new(icons::ICON_ADD).frame(false);
|
||||
let add_dir_button_response = ui.add_sized([18.0, 18.0], add_dir_button);
|
||||
if add_dir_button_response.clicked() {
|
||||
self.add_dir();
|
||||
}
|
||||
});
|
||||
|
||||
ui.with_layout(Layout::bottom_up(Align::Min), |ui| {
|
||||
let play_file_button = Button::new("Play file");
|
||||
let play_file_button_response = ui.add(play_file_button);
|
||||
if play_file_button_response.clicked() {
|
||||
self.open_file();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn draw_files(&mut self, ui: &mut Ui, area_size: Vec2) {
|
||||
let extensions = [
|
||||
"mp3", "wav", "ogg", "flac", "mp4", "m4a", "aac", "mov", "mkv", "webm", "avi",
|
||||
];
|
||||
|
||||
ui.vertical(|ui| {
|
||||
ui.horizontal(|ui| {
|
||||
let search_field = ui.add_sized(
|
||||
@@ -256,7 +260,7 @@ impl SoundpadGui {
|
||||
continue;
|
||||
}
|
||||
|
||||
if !extensions
|
||||
if !SUPPORTED_EXTENSIONS
|
||||
.contains(&entry_path.extension().unwrap_or_default().to_str().unwrap())
|
||||
{
|
||||
continue;
|
||||
|
||||
@@ -23,6 +23,10 @@ use std::{
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
const SUPPORTED_EXTENSIONS: [&str; 11] = [
|
||||
"mp3", "wav", "ogg", "flac", "mp4", "m4a", "aac", "mov", "mkv", "webm", "avi",
|
||||
];
|
||||
|
||||
struct SoundpadGui {
|
||||
pub app_state: AppState,
|
||||
pub config: GuiConfig,
|
||||
@@ -68,6 +72,13 @@ impl SoundpadGui {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn open_file(&mut self) {
|
||||
let file_dialog = FileDialog::new().add_filter("Audio File", &SUPPORTED_EXTENSIONS);
|
||||
if let Some(path) = file_dialog.pick_file() {
|
||||
self.play_file(&path);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_dir(&mut self) {
|
||||
let file_dialog = FileDialog::new();
|
||||
if let Some(path) = file_dialog.pick_folder() {
|
||||
|
||||
Reference in New Issue
Block a user