From a13f63f34272889239d1e0fcd37f9c4fb5ec983a Mon Sep 17 00:00:00 2001 From: lukeflo Date: Fri, 27 Sep 2024 23:48:46 +0200 Subject: implement scroll action for info box --- src/frontend/app.rs | 48 ++++++++++-------------------------------------- 1 file changed, 10 insertions(+), 38 deletions(-) (limited to 'src/frontend/app.rs') diff --git a/src/frontend/app.rs b/src/frontend/app.rs index 7a211e8..1a8eab7 100644 --- a/src/frontend/app.rs +++ b/src/frontend/app.rs @@ -42,9 +42,9 @@ pub struct App { pub main_biblio: BibiMain, // bibliographic data pub biblio_data: BibiData, - // list + // tag list pub tag_list: TagList, - // TODO: table items + // table items pub entry_table: EntryTable, // scroll state info buffer pub scroll_info: u16, @@ -59,14 +59,7 @@ pub struct TagList { pub tag_list_state: ListState, } -// Structure of the list items. Can be a simple string or something more elaborated -// eg: -// struct TagListItem { -// todo: String, -// info: String, -// status: Status, -// } -// where Status has to be defined explicitly somewhere else +// Structure of the list items. #[derive(Debug)] pub struct TagListItem { pub info: String, @@ -81,13 +74,10 @@ impl TagListItem { } } -// INFO: in the original template it was <&'static str> instead of impl FromIterator for TagList { - // INFO: Here to originally <&'static str> fn from_iter>(iter: I) -> Self { let tag_list_items = iter .into_iter() - // INFO: here originally not borrowed (without Ampersand'&') .map(|info| TagListItem::new(&info)) .collect(); let tag_list_state = ListState::default(); // for preselection: .with_selected(Some(0)); @@ -98,31 +88,9 @@ impl FromIterator for TagList { } } -// Iterate over vector fields with entries data to create TableItems -// Number of Strings has to match number of fields -// impl FromIterator<[String; 5]> for EntryTable { -// fn from_iter>(iter: T) -> Self { -// // Has to be Vev -// let entry_table_items = iter -// .into_iter() -// // fields in map must not be named specific -// .map(|[authors, title, year, pubtype, citekey]| { -// EntryTableItem::new(&authors, &title, &year, &pubtype, &citekey) -// }) -// .sorted_by(|a, b| a.authors.cmp(&b.authors)) -// .collect(); -// let entry_table_state = TableState::default().with_selected(0); -// Self { -// entry_table_items, -// entry_table_state, -// } -// } -// } - -// // Also possible with vector. TODO: Decide whats better +// // Also possible with vector. impl FromIterator> for EntryTable { fn from_iter>>(iter: T) -> Self { - // Has to be Vev let entry_table_items = iter .into_iter() .sorted() @@ -235,14 +203,14 @@ impl App { } pub fn scroll_info_down(&mut self) { - self.scroll_info = (self.scroll_info + 1) % 10; + self.scroll_info = (self.scroll_info + 1); } pub fn scroll_info_up(&mut self) { if self.scroll_info == 0 { {} } else { - self.scroll_info = (self.scroll_info - 1) % 10; + self.scroll_info = (self.scroll_info - 1); } } @@ -255,6 +223,7 @@ impl App { } pub fn select_next(&mut self) { + self.scroll_info = 0; match self.current_area { CurrentArea::EntryArea => self.entry_table.entry_table_state.select_next(), CurrentArea::TagArea => self.tag_list.tag_list_state.select_next(), @@ -262,6 +231,7 @@ impl App { // self.tag_list.tag_list_state.select_next(); } pub fn select_previous(&mut self) { + self.scroll_info = 0; match self.current_area { CurrentArea::EntryArea => self.entry_table.entry_table_state.select_previous(), CurrentArea::TagArea => self.tag_list.tag_list_state.select_previous(), @@ -270,6 +240,7 @@ impl App { } pub fn select_first(&mut self) { + self.scroll_info = 0; match self.current_area { CurrentArea::EntryArea => self.entry_table.entry_table_state.select_first(), CurrentArea::TagArea => self.tag_list.tag_list_state.select_first(), @@ -278,6 +249,7 @@ impl App { } pub fn select_last(&mut self) { + self.scroll_info = 0; match self.current_area { CurrentArea::EntryArea => self.entry_table.entry_table_state.select_last(), CurrentArea::TagArea => self.tag_list.tag_list_state.select_last(), -- cgit v1.2.3