Refactor UIApp to improve code readability and maintainability
This commit is contained in:
parent
04983a05c5
commit
6c74513457
1 changed files with 16 additions and 13 deletions
|
|
@ -1,10 +1,10 @@
|
||||||
use eframe::egui;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
use rfd::FileDialog;
|
|
||||||
use crate::dispatcher::Dispatcher;
|
use crate::dispatcher::Dispatcher;
|
||||||
|
use eframe::egui;
|
||||||
|
use rfd::FileDialog;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub struct UIApp {
|
pub struct UIApp {
|
||||||
picked_file: Option<PathBuf>,
|
picked_file: Option<PathBuf>,
|
||||||
addresses: Vec<String>,
|
addresses: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -21,7 +21,6 @@ impl eframe::App for UIApp {
|
||||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||||
if self.addresses.is_empty() {
|
if self.addresses.is_empty() {
|
||||||
self.addresses.push("localhost:3000".to_owned());
|
self.addresses.push("localhost:3000".to_owned());
|
||||||
|
|
||||||
}
|
}
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
let mut to_remove = Vec::new();
|
let mut to_remove = Vec::new();
|
||||||
|
|
@ -31,9 +30,11 @@ impl eframe::App for UIApp {
|
||||||
ui.text_edit_singleline(address);
|
ui.text_edit_singleline(address);
|
||||||
if ui.button("Play sound").clicked() {
|
if ui.button("Play sound").clicked() {
|
||||||
if let Some(path) = &self.picked_file {
|
if let Some(path) = &self.picked_file {
|
||||||
Dispatcher::handle_dispatch_sample(vec![address.clone()], path.to_str().unwrap().to_owned());
|
Dispatcher::handle_dispatch_sample(
|
||||||
|
vec![address.clone()],
|
||||||
}
|
path.to_str().unwrap().to_owned(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ui.button("Remove").clicked() {
|
if ui.button("Remove").clicked() {
|
||||||
to_remove.push(i);
|
to_remove.push(i);
|
||||||
|
|
@ -50,23 +51,25 @@ impl eframe::App for UIApp {
|
||||||
ui.separator();
|
ui.separator();
|
||||||
ui.add_space(25.0);
|
ui.add_space(25.0);
|
||||||
|
|
||||||
if ui.button("Pick file").clicked() {
|
if ui.button("Pick file").clicked() {
|
||||||
let file = FileDialog::new().pick_file();
|
let file = FileDialog::new().pick_file();
|
||||||
if !file.is_none() {
|
if !file.is_none() {
|
||||||
self.picked_file = file;
|
self.picked_file = file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.label(format!("Picked file: {:?}", self.picked_file));
|
ui.label(format!("Picked file: {:?}", self.picked_file));
|
||||||
|
|
||||||
ui.add_space(25.0);
|
ui.add_space(25.0);
|
||||||
ui.separator();
|
ui.separator();
|
||||||
ui.add_space(25.0);
|
ui.add_space(25.0);
|
||||||
|
|
||||||
if ui.button("Play sound").clicked() {
|
if ui.button("Play sound").clicked() {
|
||||||
if let Some(path) = &self.picked_file {
|
if let Some(path) = &self.picked_file {
|
||||||
Dispatcher::handle_dispatch_sample(self.addresses.clone(), path.to_str().unwrap().to_owned());
|
Dispatcher::handle_dispatch_sample(
|
||||||
|
self.addresses.clone(),
|
||||||
|
path.to_str().unwrap().to_owned(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue