Refactored filtering and searching logic to be more clean and added home/end support in tables.

This commit is contained in:
2023-08-08 10:50:04 -06:00
parent 864dd4e331
commit 24a36443e9
7 changed files with 223 additions and 96 deletions
+18 -1
View File
@@ -1,7 +1,6 @@
use std::cell::RefCell;
use std::fmt::{Debug, Display, Formatter};
use log::debug;
use serde::Deserialize;
use tui::widgets::TableState;
@@ -25,6 +24,8 @@ pub enum Route {
pub trait Scrollable {
fn scroll_down(&mut self);
fn scroll_up(&mut self);
fn scroll_to_top(&mut self);
fn scroll_to_bottom(&mut self);
}
pub struct StatefulTable<T> {
@@ -102,6 +103,14 @@ impl<T> Scrollable for StatefulTable<T> {
self.state.select(Some(selected_row));
}
fn scroll_to_top(&mut self) {
self.state.select(Some(0));
}
fn scroll_to_bottom(&mut self) {
self.state.select(Some(self.items.len() - 1));
}
}
#[derive(Default)]
@@ -134,6 +143,14 @@ impl Scrollable for ScrollableText {
self.offset -= 1;
}
}
fn scroll_to_top(&mut self) {
self.offset = 0;
}
fn scroll_to_bottom(&mut self) {
self.offset = (self.items.len() - 1) as u16;
}
}
#[derive(Default, Deserialize, Debug, Clone, PartialEq, Eq)]