Partial matrix implementation
This commit is contained in:
@@ -1 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
|
/.idea/
|
||||||
|
Cargo.lock
|
||||||
|
|||||||
+8
-2
@@ -5,10 +5,10 @@ use chrono::{DateTime, Utc};
|
|||||||
use strum::EnumIter;
|
use strum::EnumIter;
|
||||||
|
|
||||||
use crate::app::{App, Route};
|
use crate::app::{App, Route};
|
||||||
|
use crate::models::{ScrollableText, StatefulMatrix, StatefulTable, TabRoute, TabState};
|
||||||
use crate::models::radarr_models::{
|
use crate::models::radarr_models::{
|
||||||
Collection, CollectionMovie, Credit, DiskSpace, DownloadRecord, Movie, MovieHistoryItem,
|
Collection, CollectionMovie, Credit, DiskSpace, DownloadRecord, Movie, MovieHistoryItem,
|
||||||
};
|
};
|
||||||
use crate::models::{ScrollableText, StatefulTable, TabRoute, TabState};
|
|
||||||
use crate::network::radarr_network::RadarrEvent;
|
use crate::network::radarr_network::RadarrEvent;
|
||||||
|
|
||||||
pub struct RadarrData {
|
pub struct RadarrData {
|
||||||
@@ -29,6 +29,7 @@ pub struct RadarrData {
|
|||||||
pub collections: StatefulTable<Collection>,
|
pub collections: StatefulTable<Collection>,
|
||||||
pub filtered_collections: StatefulTable<Collection>,
|
pub filtered_collections: StatefulTable<Collection>,
|
||||||
pub collection_movies: StatefulTable<CollectionMovie>,
|
pub collection_movies: StatefulTable<CollectionMovie>,
|
||||||
|
pub calendar: StatefulMatrix<>
|
||||||
pub main_tabs: TabState,
|
pub main_tabs: TabState,
|
||||||
pub movie_info_tabs: TabState,
|
pub movie_info_tabs: TabState,
|
||||||
pub search: String,
|
pub search: String,
|
||||||
@@ -94,7 +95,7 @@ impl Default for RadarrData {
|
|||||||
TabRoute {
|
TabRoute {
|
||||||
title: "Library".to_owned(),
|
title: "Library".to_owned(),
|
||||||
route: ActiveRadarrBlock::Movies.into(),
|
route: ActiveRadarrBlock::Movies.into(),
|
||||||
help: "<↑↓> scroll | <s> search | <f> filter | <enter> details | <esc> cancel filter | ←→ change tab "
|
help: "<↑↓> scroll | <s> search | <f> filter | <enter> details | <esc> cancel filter | <del> delete | ←→ change tab "
|
||||||
.to_owned(),
|
.to_owned(),
|
||||||
},
|
},
|
||||||
TabRoute {
|
TabRoute {
|
||||||
@@ -108,6 +109,11 @@ impl Default for RadarrData {
|
|||||||
help: "<↑↓> scroll | <s> search | <f> filter | <enter> details | <esc> cancel filter | ←→ change tab "
|
help: "<↑↓> scroll | <s> search | <f> filter | <enter> details | <esc> cancel filter | ←→ change tab "
|
||||||
.to_owned(),
|
.to_owned(),
|
||||||
},
|
},
|
||||||
|
TabRoute {
|
||||||
|
title: "Calendar".to_owned(),
|
||||||
|
route: ActiveRadarrBlock::Calendar.into(),
|
||||||
|
help: "<↑↓> scroll | <enter> details | ←→ change tab ".to_owned()
|
||||||
|
}
|
||||||
]),
|
]),
|
||||||
movie_info_tabs: TabState::new(vec![
|
movie_info_tabs: TabState::new(vec![
|
||||||
TabRoute {
|
TabRoute {
|
||||||
|
|||||||
@@ -113,6 +113,61 @@ impl<T> Scrollable for StatefulTable<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct StatefulMatrix<T> {
|
||||||
|
pub selection: (usize, usize),
|
||||||
|
pub items: Vec<Vec<T>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Scrollable for StatefulMatrix<T> {
|
||||||
|
fn scroll_down(&mut self) {
|
||||||
|
if self.selection.0 >= self.items.len() - 1 {
|
||||||
|
self.selection.0 = 0;
|
||||||
|
} else {
|
||||||
|
self.selection.0 += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scroll_up(&mut self) {
|
||||||
|
if self.selection.0 == 0 {
|
||||||
|
self.selection.0 = self.items.len() - 1;
|
||||||
|
} else {
|
||||||
|
self.selection.0 -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scroll_to_top(&mut self) {
|
||||||
|
self.selection.0 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scroll_to_bottom(&mut self) {
|
||||||
|
self.selection.0 = self.items.len() - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> StatefulMatrix<T> {
|
||||||
|
pub fn current_selection(&self) -> &T {
|
||||||
|
let (x, y) = self.selection;
|
||||||
|
&self.items[x][y]
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn scroll_left(&mut self) {
|
||||||
|
if self.selection.1 == 0 {
|
||||||
|
self.selection.1 = self.items[0].len() - 1;
|
||||||
|
} else {
|
||||||
|
self.selection.1 -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn scroll_right(&mut self) {
|
||||||
|
if self.selection.1 >= self.items[0].len() - 1 {
|
||||||
|
self.selection.1 = 0;
|
||||||
|
} else {
|
||||||
|
self.selection.1 += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct ScrollableText {
|
pub struct ScrollableText {
|
||||||
pub items: Vec<String>,
|
pub items: Vec<String>,
|
||||||
|
|||||||
Reference in New Issue
Block a user