Display album name for playable objects (#268)
* display album name * give proper name to the space key fixes #266 * use 50% for center offset Co-authored-by: Henrik Friedrichsen <henrik@affekt.org>
This commit is contained in:
@@ -159,6 +159,10 @@ impl ListItem for Album {
|
||||
format!("{}", self)
|
||||
}
|
||||
|
||||
fn display_center(&self) -> String {
|
||||
"".to_string()
|
||||
}
|
||||
|
||||
fn display_right(&self, library: Arc<Library>) -> String {
|
||||
let saved = if library.is_saved_album(self) {
|
||||
if library.use_nerdfont {
|
||||
|
||||
@@ -148,6 +148,10 @@ impl ListItem for Artist {
|
||||
format!("{}", self)
|
||||
}
|
||||
|
||||
fn display_center(&self) -> String {
|
||||
"".to_string()
|
||||
}
|
||||
|
||||
fn display_right(&self, library: Arc<Library>) -> String {
|
||||
let followed = if library.is_followed_artist(self) {
|
||||
if library.use_nerdfont {
|
||||
|
||||
@@ -71,6 +71,10 @@ impl ListItem for Episode {
|
||||
self.name.clone()
|
||||
}
|
||||
|
||||
fn display_center(&self) -> String {
|
||||
"".to_string()
|
||||
}
|
||||
|
||||
fn display_right(&self, _library: Arc<Library>) -> String {
|
||||
format!("{} [{}]", self.duration_str(), self.release_date)
|
||||
}
|
||||
|
||||
@@ -76,6 +76,10 @@ impl ListItem for Playable {
|
||||
self.as_listitem().display_left()
|
||||
}
|
||||
|
||||
fn display_center(&self) -> String {
|
||||
self.as_listitem().display_center()
|
||||
}
|
||||
|
||||
fn display_right(&self, library: Arc<Library>) -> String {
|
||||
self.as_listitem().display_right(library)
|
||||
}
|
||||
|
||||
@@ -128,6 +128,10 @@ impl ListItem for Playlist {
|
||||
self.name.clone()
|
||||
}
|
||||
|
||||
fn display_center(&self) -> String {
|
||||
"".to_string()
|
||||
}
|
||||
|
||||
fn display_right(&self, library: Arc<Library>) -> String {
|
||||
let saved = if library.is_saved_playlist(self) {
|
||||
if library.use_nerdfont {
|
||||
|
||||
@@ -92,6 +92,10 @@ impl ListItem for Show {
|
||||
format!("{}", self)
|
||||
}
|
||||
|
||||
fn display_center(&self) -> String {
|
||||
"".to_string()
|
||||
}
|
||||
|
||||
fn display_right(&self, library: Arc<Library>) -> String {
|
||||
let saved = if library.is_saved_show(self) {
|
||||
if library.use_nerdfont {
|
||||
|
||||
@@ -153,6 +153,10 @@ impl ListItem for Track {
|
||||
format!("{}", self)
|
||||
}
|
||||
|
||||
fn display_center(&self) -> String {
|
||||
format!("{}", self.album)
|
||||
}
|
||||
|
||||
fn display_right(&self, library: Arc<Library>) -> String {
|
||||
let saved = if library.is_saved_track(&Playable::Track(self.clone())) {
|
||||
if library.use_nerdfont {
|
||||
|
||||
@@ -15,6 +15,7 @@ use crate::track::Track;
|
||||
pub trait ListItem: Sync + Send + 'static {
|
||||
fn is_playing(&self, queue: Arc<Queue>) -> bool;
|
||||
fn display_left(&self) -> String;
|
||||
fn display_center(&self) -> String;
|
||||
fn display_right(&self, library: Arc<Library>) -> String;
|
||||
fn play(&mut self, queue: Arc<Queue>);
|
||||
fn queue(&mut self, queue: Arc<Queue>);
|
||||
|
||||
@@ -202,16 +202,19 @@ impl<I: ListItem> View for ListView<I> {
|
||||
};
|
||||
|
||||
let left = item.display_left();
|
||||
let center = item.display_center();
|
||||
let right = item.display_right(self.library.clone());
|
||||
|
||||
let center_offset = printer.size.x / 2;
|
||||
|
||||
// draw left string
|
||||
printer.with_color(style, |printer| {
|
||||
printer.print_hline((0, 0), printer.size.x, " ");
|
||||
printer.print((0, 0), &left);
|
||||
});
|
||||
|
||||
// draw ".." to indicate a cut off string
|
||||
let max_length = printer.size.x.saturating_sub(right.width() + 1);
|
||||
// left string cut off indicator
|
||||
let max_length = center_offset.saturating_sub(1);
|
||||
if max_length < left.width() {
|
||||
let offset = max_length.saturating_sub(1);
|
||||
printer.with_color(style, |printer| {
|
||||
@@ -219,6 +222,19 @@ impl<I: ListItem> View for ListView<I> {
|
||||
});
|
||||
}
|
||||
|
||||
printer.with_color(style, |printer| {
|
||||
printer.print((center_offset, 0), ¢er);
|
||||
});
|
||||
|
||||
// center string cut off indicator
|
||||
let max_length = printer.size.x.saturating_sub(right.width() + 1);
|
||||
if max_length < center_offset + center.width() {
|
||||
let offset = max_length.saturating_sub(1);
|
||||
printer.with_color(style, |printer| {
|
||||
printer.print((offset, 0), "..");
|
||||
});
|
||||
}
|
||||
|
||||
// draw right string
|
||||
let offset = HAlign::Right.get_offset(right.width(), printer.size.x);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user