Remade the window adding machanism, added playlist add window
This commit is contained in:
@@ -6,15 +6,22 @@ use crate::GuiState;
|
||||
mod debug;
|
||||
mod error;
|
||||
mod settings;
|
||||
mod add_song;
|
||||
mod new_song;
|
||||
mod new_playlist;
|
||||
|
||||
lazy_static::lazy_static!(
|
||||
static ref WINDOWS: Arc<Mutex<HashMap<WindowId, Box<dyn Window>>>> = Arc::new(Mutex::new(HashMap::new()));
|
||||
static ref OPEN_WINDOWS: Arc<Mutex<HashSet<WindowId>>> = Arc::new(Mutex::new(HashSet::new()));
|
||||
|
||||
);
|
||||
|
||||
pub trait Window: std::fmt::Debug + Send {
|
||||
fn draw(&mut self, ui: &mut egui::Ui, state: &mut GuiState) -> crate::Result<()>;
|
||||
fn id() -> WindowId where Self: Sized;
|
||||
fn default_title() -> &'static str where Self: Sized;
|
||||
fn close(&self) where Self: Sized{
|
||||
OPEN_WINDOWS.lock().unwrap().remove(&Self::id());
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Hash, PartialEq, PartialOrd, Ord, Eq)]
|
||||
@@ -22,7 +29,10 @@ pub enum WindowId {
|
||||
Settings,
|
||||
Error,
|
||||
#[cfg(debug_assertions)]
|
||||
Debug
|
||||
Debug,
|
||||
NewPlaylist,
|
||||
NewSong,
|
||||
AddSongToPl,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -40,18 +50,21 @@ impl Windows {
|
||||
}
|
||||
|
||||
pub fn add_all_windows(&mut self) {
|
||||
self.add_new_window(WindowId::Error, "Error!", Box::<error::ErrorW>::default());
|
||||
self.add_new_window(WindowId::Settings, "Settings", Box::<settings::SettingsW>::default());
|
||||
#[cfg(debug_assertions)]
|
||||
self.add_new_window(WindowId::Debug, "Debug", Box::<debug::DebugW>::default());
|
||||
self.add_new_window::<debug::DebugW>();
|
||||
self.add_new_window::<error::ErrorW>();
|
||||
self.add_new_window::<settings::SettingsW>();
|
||||
self.add_new_window::<add_song::AddSongW>();
|
||||
self.add_new_window::<new_song::NewSongW>();
|
||||
self.add_new_window::<new_playlist::NewPlaylistW>();
|
||||
}
|
||||
|
||||
pub fn add_new_window(&mut self, id: WindowId, title: &str, cb: Box<dyn Window>) {
|
||||
pub fn add_new_window<WT: Window + Default + 'static>(&mut self) {
|
||||
let builder = ViewportBuilder::default()
|
||||
.with_window_type(egui::X11WindowType::Dialog)
|
||||
.with_title(title);
|
||||
self.windows.insert(id.clone(), (ViewportId::from_hash_of(id.clone()), builder));
|
||||
WINDOWS.lock().unwrap().insert(id, cb);
|
||||
.with_title(WT::default_title());
|
||||
self.windows.insert(WT::id(), (ViewportId::from_hash_of(WT::id()), builder));
|
||||
WINDOWS.lock().unwrap().insert(WT::id(), Box::<WT>::default());
|
||||
}
|
||||
|
||||
pub fn draw_all(&mut self, ctx: &egui::Context, state: &mut GuiState) {
|
||||
|
||||
Reference in New Issue
Block a user