Use ViewExt.title() in TabView
Instead of storing a separate copy of the view title. Additionally, rename `ViewExt.set_title()` to `ViewExt.with_title()` as it consumes `self` and returns ownership.
This commit is contained in:
@@ -277,7 +277,7 @@ impl ListItem for Album {
|
||||
queue.clone(),
|
||||
library.clone(),
|
||||
)
|
||||
.set_title(format!("Similar to Album \"{}\"", self.title))
|
||||
.with_title(&format!("Similar to Album \"{}\"", self.title))
|
||||
.into_boxed_view_ext()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ impl ListItem for Artist {
|
||||
queue.clone(),
|
||||
library.clone(),
|
||||
)
|
||||
.set_title(format!("Similar to Artist \"{}\"", self.name,))
|
||||
.with_title(&format!("Similar to Artist \"{}\"", self.name))
|
||||
.into_boxed_view_ext()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ impl ListItem for Playlist {
|
||||
queue.clone(),
|
||||
library.clone(),
|
||||
)
|
||||
.set_title(format!("Similar to Tracks in \"{}\"", self.name,))
|
||||
.with_title(&format!("Similar to Tracks in \"{}\"", self.name))
|
||||
.into_boxed_view_ext()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ impl ListItem for Track {
|
||||
queue.clone(),
|
||||
library.clone(),
|
||||
)
|
||||
.set_title(format!(
|
||||
.with_title(&format!(
|
||||
"Similar to \"{} - {}\"",
|
||||
self.artists.join(", "),
|
||||
self.title
|
||||
|
||||
@@ -40,17 +40,16 @@ impl AlbumView {
|
||||
let tabs = TabView::new()
|
||||
.tab(
|
||||
"tracks",
|
||||
"Tracks",
|
||||
ListView::new(
|
||||
Arc::new(RwLock::new(tracks)),
|
||||
queue.clone(),
|
||||
library.clone(),
|
||||
),
|
||||
)
|
||||
.with_title("Tracks"),
|
||||
)
|
||||
.tab(
|
||||
"artists",
|
||||
"Artists",
|
||||
ListView::new(Arc::new(RwLock::new(artists)), queue, library),
|
||||
ListView::new(Arc::new(RwLock::new(artists)), queue, library).with_title("Artists"),
|
||||
);
|
||||
|
||||
Self { album, tabs }
|
||||
|
||||
@@ -68,28 +68,26 @@ impl ArtistView {
|
||||
|
||||
tabs.add_tab(
|
||||
"tracks",
|
||||
"Saved Tracks",
|
||||
ListView::new(
|
||||
Arc::new(RwLock::new(tracks)),
|
||||
queue.clone(),
|
||||
library.clone(),
|
||||
),
|
||||
)
|
||||
.with_title("Saved Tracks"),
|
||||
);
|
||||
}
|
||||
|
||||
tabs.add_tab(
|
||||
"top_tracks",
|
||||
"Top 10",
|
||||
ListView::new(top_tracks, queue.clone(), library.clone()),
|
||||
ListView::new(top_tracks, queue.clone(), library.clone()).with_title("Top 10"),
|
||||
);
|
||||
|
||||
tabs.add_tab("albums", "Albums", albums_view);
|
||||
tabs.add_tab("singles", "Singles", singles_view);
|
||||
tabs.add_tab("albums", albums_view.with_title("Albums"));
|
||||
tabs.add_tab("singles", singles_view.with_title("Singles"));
|
||||
|
||||
tabs.add_tab(
|
||||
"related",
|
||||
"Related Artists",
|
||||
ListView::new(related, queue, library),
|
||||
ListView::new(related, queue, library).with_title("Related Artists"),
|
||||
);
|
||||
|
||||
Self {
|
||||
|
||||
@@ -33,28 +33,27 @@ impl LibraryView {
|
||||
match tab {
|
||||
LibraryTab::Tracks => tabview.add_tab(
|
||||
"tracks",
|
||||
"Tracks",
|
||||
ListView::new(library.tracks.clone(), queue.clone(), library.clone()),
|
||||
ListView::new(library.tracks.clone(), queue.clone(), library.clone())
|
||||
.with_title("Tracks"),
|
||||
),
|
||||
LibraryTab::Albums => tabview.add_tab(
|
||||
"albums",
|
||||
"Albums",
|
||||
ListView::new(library.albums.clone(), queue.clone(), library.clone()),
|
||||
ListView::new(library.albums.clone(), queue.clone(), library.clone())
|
||||
.with_title("Albums"),
|
||||
),
|
||||
LibraryTab::Artists => tabview.add_tab(
|
||||
"artists",
|
||||
"Artists",
|
||||
ListView::new(library.artists.clone(), queue.clone(), library.clone()),
|
||||
ListView::new(library.artists.clone(), queue.clone(), library.clone())
|
||||
.with_title("Artists"),
|
||||
),
|
||||
LibraryTab::Playlists => tabview.add_tab(
|
||||
"playlists",
|
||||
"Playlists",
|
||||
PlaylistsView::new(queue.clone(), library.clone()),
|
||||
),
|
||||
LibraryTab::Podcasts => tabview.add_tab(
|
||||
"podcasts",
|
||||
"Podcasts",
|
||||
ListView::new(library.shows.clone(), queue.clone(), library.clone()),
|
||||
ListView::new(library.shows.clone(), queue.clone(), library.clone())
|
||||
.with_title("Podcasts"),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,8 +75,8 @@ impl<I: ListItem> ListView<I> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_title(mut self, title: String) -> Self {
|
||||
self.title = title;
|
||||
pub fn with_title(mut self, title: &str) -> Self {
|
||||
self.title = title.to_string();
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,10 @@ impl ViewWrapper for PlaylistsView {
|
||||
}
|
||||
|
||||
impl ViewExt for PlaylistsView {
|
||||
fn title(&self) -> String {
|
||||
"Playlists".to_string()
|
||||
}
|
||||
|
||||
fn on_command(&mut self, s: &mut Cursive, cmd: &Command) -> Result<CommandResult, String> {
|
||||
if let Command::Delete = cmd {
|
||||
if let Some(dialog) = self.delete_dialog() {
|
||||
|
||||
@@ -72,12 +72,12 @@ impl SearchResultsView {
|
||||
let pagination_episodes = list_episodes.get_pagination().clone();
|
||||
|
||||
let tabs = TabView::new()
|
||||
.tab("tracks", "Tracks", list_tracks)
|
||||
.tab("albums", "Albums", list_albums)
|
||||
.tab("artists", "Artists", list_artists)
|
||||
.tab("playlists", "Playlists", list_playlists)
|
||||
.tab("shows", "Podcasts", list_shows)
|
||||
.tab("episodes", "Podcast Episodes", list_episodes);
|
||||
.tab("tracks", list_tracks.with_title("Tracks"))
|
||||
.tab("albums", list_albums.with_title("Albums"))
|
||||
.tab("artists", list_artists.with_title("Artists"))
|
||||
.tab("playlists", list_playlists.with_title("Playlists"))
|
||||
.tab("shows", list_shows.with_title("Podcasts"))
|
||||
.tab("episodes", list_episodes.with_title("Podcast Episodes"));
|
||||
|
||||
let mut view = SearchResultsView {
|
||||
search_term,
|
||||
|
||||
@@ -13,7 +13,6 @@ use crate::commands::CommandResult;
|
||||
use crate::traits::{IntoBoxedViewExt, ViewExt};
|
||||
|
||||
pub struct Tab {
|
||||
title: String,
|
||||
view: Box<dyn ViewExt>,
|
||||
}
|
||||
|
||||
@@ -34,17 +33,16 @@ impl TabView {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_tab<S: Into<String>, V: IntoBoxedViewExt>(&mut self, id: S, title: S, view: V) {
|
||||
pub fn add_tab<S: Into<String>, V: IntoBoxedViewExt>(&mut self, id: S, view: V) {
|
||||
let tab = Tab {
|
||||
title: title.into(),
|
||||
view: view.into_boxed_view_ext(),
|
||||
};
|
||||
self.tabs.push(tab);
|
||||
self.ids.insert(id.into(), self.tabs.len() - 1);
|
||||
}
|
||||
|
||||
pub fn tab<S: Into<String>, V: IntoBoxedViewExt>(mut self, id: S, title: S, view: V) -> Self {
|
||||
self.add_tab(id, title, view);
|
||||
pub fn tab<S: Into<String>, V: IntoBoxedViewExt>(mut self, id: S, view: V) -> Self {
|
||||
self.add_tab(id, view);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -81,11 +79,12 @@ impl View for TabView {
|
||||
width += printer.size.x % self.tabs.len();
|
||||
}
|
||||
|
||||
let offset = HAlign::Center.get_offset(tab.title.width(), width);
|
||||
let title = tab.view.title();
|
||||
let offset = HAlign::Center.get_offset(title.width(), width);
|
||||
|
||||
printer.with_color(style, |printer| {
|
||||
printer.print_hline((i * tabwidth, 0), width, " ");
|
||||
printer.print((i * tabwidth + offset, 0), &tab.title);
|
||||
printer.print((i * tabwidth + offset, 0), &title);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user