Skip to content

Commit

Permalink
Display album name for playable objects (#268)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
mtshrmn and hrkfdn committed Sep 28, 2020
1 parent cded15f commit 77e5de5
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/album.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/artist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/episode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions src/playable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions src/playlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>);
Expand Down
20 changes: 18 additions & 2 deletions src/ui/listview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,23 +202,39 @@ 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| {
printer.print((offset, 0), "..");
});
}

printer.with_color(style, |printer| {
printer.print((center_offset, 0), &center);
});

// 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);

Expand Down

0 comments on commit 77e5de5

Please sign in to comment.