use std::sync::Arc; use cursive::view::{View, ViewWrapper}; use cursive::views::NamedView; use cursive::Cursive; use crate::command::Command; use crate::commands::CommandResult; use crate::library::Library; use crate::model::album::Album; use crate::model::artist::Artist; use crate::model::track::Track; use crate::queue::Queue; pub trait ListItem: Sync + Send + 'static { fn is_playing(&self, queue: Arc) -> bool; fn display_left(&self) -> String; fn display_center(&self, _library: Arc) -> String { "".to_string() } fn display_right(&self, library: Arc) -> String; fn play(&mut self, queue: Arc); fn queue(&mut self, queue: Arc); fn play_next(&mut self, queue: Arc); fn toggle_saved(&mut self, library: Arc); fn save(&mut self, library: Arc); fn unsave(&mut self, library: Arc); fn open(&self, queue: Arc, library: Arc) -> Option>; fn open_recommendations( &mut self, _queue: Arc, _library: Arc, ) -> Option> { None } fn share_url(&self) -> Option; fn album(&self, _queue: Arc) -> Option { None } fn artists(&self) -> Option> { None } fn track(&self) -> Option { None } fn as_listitem(&self) -> Box; } pub trait ViewExt: View { fn title(&self) -> String { "".into() } fn title_sub(&self) -> String { "".into() } fn on_leave(&self) {} fn on_command(&mut self, _s: &mut Cursive, _cmd: &Command) -> Result { Ok(CommandResult::Ignored) } } impl ViewExt for NamedView { fn title(&self) -> String { self.with_view(|v| v.title()).unwrap_or_default() } fn title_sub(&self) -> String { self.with_view(|v| v.title_sub()).unwrap_or_default() } fn on_leave(&self) { self.with_view(|v| v.on_leave()); } fn on_command(&mut self, s: &mut Cursive, cmd: &Command) -> Result { self.with_view_mut(move |v| v.on_command(s, cmd)).unwrap() } } pub trait IntoBoxedViewExt { fn into_boxed_view_ext(self) -> Box; } impl IntoBoxedViewExt for V { fn into_boxed_view_ext(self) -> Box { Box::new(self) } }