137 lines
5.7 KiB
Rust
137 lines
5.7 KiB
Rust
use std::str::FromStr;
|
|
|
|
use egui::{Sense, Vec2};
|
|
use xmpd_manifest::{song::{Song, SourceType}, store::BaseStore};
|
|
|
|
use crate::{components::{CompGetter, toast::{Toast, ToastType}}, windows::WindowId};
|
|
|
|
use super::Window;
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
pub struct NewSongW {
|
|
name: String,
|
|
author: String,
|
|
source_t: SourceType,
|
|
source_url: String,
|
|
source_url_old: String,
|
|
}
|
|
|
|
impl Window for NewSongW {
|
|
fn id() -> super::WindowId where Self: Sized {
|
|
super::WindowId::NewSong
|
|
}
|
|
fn default_title() -> &'static str where Self: Sized {
|
|
"New Song"
|
|
}
|
|
fn draw(&mut self, ui: &mut egui::Ui, state: &mut crate::GuiState) -> crate::Result<()> {
|
|
let theme = xmpd_settings::Settings::get()?.theme.clone();
|
|
let img_size = 64.0;
|
|
let img_spacing = 10.0;
|
|
ui.vertical(|ui| {
|
|
let mut rect = egui::Rect::ZERO;
|
|
rect.set_width(img_size);
|
|
rect.set_height(img_size);
|
|
rect.set_top(img_spacing);
|
|
rect.set_left(img_spacing);
|
|
let rect_int = ui.interact(rect, "new_playlist_w".into(), Sense::click());
|
|
if rect_int.hovered() {
|
|
ui.allocate_ui_at_rect(rect, |ui| {
|
|
ui.group(|ui| {
|
|
let img = egui::Image::new(crate::data::PLUS_ICON)
|
|
.tint(theme.accent_color)
|
|
.fit_to_exact_size(Vec2::new(img_size, img_size));
|
|
//.paint_at(ui, rect);
|
|
ui.add(img);
|
|
});
|
|
});
|
|
|
|
} else {
|
|
ui.allocate_ui_at_rect(rect, |ui| {
|
|
ui.group(|ui| {
|
|
let img = egui::Image::new(crate::data::NOTE_ICON)
|
|
.tint(theme.accent_color)
|
|
.fit_to_exact_size(Vec2::new(img_size, img_size));
|
|
//.paint_at(ui, rect);
|
|
ui.add(img);
|
|
});
|
|
});
|
|
}
|
|
if rect_int.clicked() {
|
|
// TODO: Add a way to add custom icons
|
|
Toast::get().unwrap().show_toast("Not Implemented", "Adding icons to songs is not implemented", ToastType::Error);
|
|
}
|
|
ui.add_space(img_spacing);
|
|
ui.horizontal(|ui| {
|
|
ui.label("Name: ");
|
|
ui.text_edit_singleline(&mut self.name);
|
|
});
|
|
ui.horizontal(|ui| {
|
|
ui.label("Author: ");
|
|
ui.text_edit_singleline(&mut self.author);
|
|
});
|
|
ui.horizontal(|ui| {
|
|
ui.label("Source Type: ");
|
|
egui::ComboBox::new("new_song_song_t_sel", "")
|
|
.selected_text(self.source_t.to_string())
|
|
.show_ui(ui, |ui| {
|
|
ui.selectable_value(&mut self.source_t, SourceType::Youtube, SourceType::Youtube.to_string());
|
|
ui.selectable_value(&mut self.source_t, SourceType::Spotify, SourceType::Spotify.to_string());
|
|
ui.selectable_value(&mut self.source_t, SourceType::Soundcloud, SourceType::Soundcloud.to_string());
|
|
//ui.selectable_value(&mut self.source_t, SourceType::HttpBare, SourceType::HttpBare.to_string());
|
|
//ui.selectable_value(&mut self.source_t, SourceType::HttpZip, SourceType::HttpZip.to_string());
|
|
//ui.selectable_value(&mut self.source_t, SourceType::Http7z, SourceType::Http7z.to_string());
|
|
}
|
|
);
|
|
});
|
|
ui.horizontal(|ui| {
|
|
ui.label("Source URL: ");
|
|
ui.text_edit_singleline(&mut self.source_url);
|
|
if self.source_url != self.source_url_old {
|
|
if let Some(t) = SourceType::from_url(&handle_error_ui!(url::Url::from_str(&self.source_url))) {
|
|
self.source_t = t;
|
|
}
|
|
}
|
|
});
|
|
|
|
ui.with_layout(egui::Layout::bottom_up(egui::Align::Max), |ui| {
|
|
ui.add_space(3.0);
|
|
ui.horizontal(|ui| {
|
|
ui.add_space(3.0);
|
|
if ui.button("Close").clicked() {
|
|
self.author = String::from("New Song");
|
|
self.name = String::from("Unknown");
|
|
self.source_t = SourceType::Youtube;
|
|
self.source_url = String::default();
|
|
state.windows.toggle(&WindowId::NewSong, false);
|
|
}
|
|
|
|
if ui.button("Add").clicked() {
|
|
let mut s = handle_error_ui!(Song::new_from_str(&self.source_url, self.source_t));
|
|
s.set_name(&self.name);
|
|
s.set_author(&self.author);
|
|
state.manifest.store_mut().get_songs_mut().insert(uuid::Uuid::new_v4(), s);
|
|
|
|
self.author = String::from("New Song");
|
|
self.name = String::from("Unknown");
|
|
self.source_t = SourceType::Youtube;
|
|
self.source_url = String::default();
|
|
}
|
|
|
|
if ui.button("Cancel").clicked() {
|
|
self.author = String::from("New Song");
|
|
self.name = String::from("Unknown");
|
|
self.source_t = SourceType::Youtube;
|
|
self.source_url = String::default();
|
|
state.windows.toggle(&WindowId::NewSong, false);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
Ok(())
|
|
}
|
|
fn set_value<V>(&mut self, _: String, _: Box<V>) where Self: Sized {
|
|
|
|
}
|
|
}
|