Refactor UIApp to improve code readability and maintainability

This commit is contained in:
cediackermann 2025-01-27 11:58:01 +01:00
parent 04983a05c5
commit 6c74513457
No known key found for this signature in database
GPG key ID: 00C575502DDA2430

View file

@ -1,7 +1,7 @@
use eframe::egui;
use std::path::PathBuf;
use rfd::FileDialog;
use crate::dispatcher::Dispatcher;
use eframe::egui;
use rfd::FileDialog;
use std::path::PathBuf;
pub struct UIApp {
picked_file: Option<PathBuf>,
@ -21,7 +21,6 @@ impl eframe::App for UIApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
if self.addresses.is_empty() {
self.addresses.push("localhost:3000".to_owned());
}
egui::CentralPanel::default().show(ctx, |ui| {
let mut to_remove = Vec::new();
@ -31,8 +30,10 @@ impl eframe::App for UIApp {
ui.text_edit_singleline(address);
if ui.button("Play sound").clicked() {
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() {
@ -50,7 +51,7 @@ impl eframe::App for UIApp {
ui.separator();
ui.add_space(25.0);
if ui.button("Pick file").clicked() {
if ui.button("Pick file").clicked() {
let file = FileDialog::new().pick_file();
if !file.is_none() {
self.picked_file = file;
@ -65,8 +66,10 @@ impl eframe::App for UIApp {
if ui.button("Play sound").clicked() {
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(),
);
}
}
});