Implemented Library and Download tabs!

This commit is contained in:
2023-08-08 10:50:04 -06:00
parent d856e84b93
commit c16f234088
10 changed files with 257 additions and 61 deletions
+40
View File
@@ -1,5 +1,7 @@
use tui::widgets::TableState;
use crate::app::Route;
pub trait Scrollable {
fn scroll_down(&mut self);
fn scroll_up(&mut self);
@@ -105,3 +107,41 @@ impl Scrollable for ScrollableText {
}
}
}
#[derive(Clone)]
pub struct TabRoute {
pub title: String,
pub route: Route,
}
pub struct TabState {
pub tabs: Vec<TabRoute>,
pub index: usize,
}
impl TabState {
pub fn new(tabs: Vec<TabRoute>) -> TabState {
TabState { tabs, index: 0 }
}
pub fn set_index(&mut self, index: usize) -> &TabRoute {
self.index = index;
&self.tabs[self.index]
}
pub fn get_active_route(&self) -> &Route {
&self.tabs[self.index].route
}
pub fn next(&mut self) {
self.index = (self.index + 1) % self.tabs.len();
}
pub fn previous(&mut self) {
if self.index > 0 {
self.index -= 1;
} else {
self.index = self.tabs.len() - 1;
}
}
}