aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlukeflo2024-10-11 14:05:34 +0200
committerlukeflo2024-10-12 22:41:38 +0200
commitd7bc5105f0fb572beb2ae4e5b033a343ae12f2dc (patch)
tree471932b621f1e4cbedf9eeaf4bb7ead74f0af95f /src
parent1ad9a97e9a25622a9946cb9c55705922c42d9149 (diff)
downloadbibiman-d7bc5105f0fb572beb2ae4e5b033a343ae12f2dc.tar.gz
bibiman-d7bc5105f0fb572beb2ae4e5b033a343ae12f2dc.zip
scrollbar for entries and keywords. scroll symbols for abstract first steps
Diffstat (limited to 'src')
-rw-r--r--src/frontend/app.rs22
-rw-r--r--src/frontend/entries.rs21
-rw-r--r--src/frontend/handler.rs36
-rw-r--r--src/frontend/ui.rs64
4 files changed, 101 insertions, 42 deletions
diff --git a/src/frontend/app.rs b/src/frontend/app.rs
index 26b9a13..ee2ab05 100644
--- a/src/frontend/app.rs
+++ b/src/frontend/app.rs
@@ -175,15 +175,25 @@ impl App {
}
pub fn scroll_info_down(&mut self) {
- self.scroll_info = self.scroll_info + 1;
+ // self.entry_table.entry_info_scroll = self.entry_table.entry_info_scroll + 1;
+ self.entry_table.entry_info_scroll = self.entry_table.entry_info_scroll.saturating_add(1);
+ self.entry_table.entry_info_scroll_state = self
+ .entry_table
+ .entry_info_scroll_state
+ .position(self.entry_table.entry_info_scroll.into());
}
pub fn scroll_info_up(&mut self) {
- if self.scroll_info == 0 {
- {}
- } else {
- self.scroll_info = self.scroll_info - 1;
- }
+ // if self.entry_table.entry_info_scroll == 0 {
+ // {}
+ // } else {
+ // self.entry_table.entry_info_scroll = self.entry_table.entry_info_scroll - 1;
+ // }
+ self.entry_table.entry_info_scroll = self.entry_table.entry_info_scroll.saturating_sub(1);
+ self.entry_table.entry_info_scroll_state = self
+ .entry_table
+ .entry_info_scroll_state
+ .position(self.entry_table.entry_info_scroll.into());
}
// Search Area
diff --git a/src/frontend/entries.rs b/src/frontend/entries.rs
index b0bb0b7..081de4c 100644
--- a/src/frontend/entries.rs
+++ b/src/frontend/entries.rs
@@ -31,6 +31,8 @@ pub struct EntryTable {
pub entry_table_items: Vec<EntryTableItem>,
pub entry_table_state: TableState,
pub entry_scroll_state: ScrollbarState,
+ pub entry_info_scroll: u16,
+ pub entry_info_scroll_state: ScrollbarState,
}
impl FromIterator<Vec<String>> for EntryTable {
@@ -49,10 +51,13 @@ impl FromIterator<Vec<String>> for EntryTable {
.collect();
let entry_table_state = TableState::default().with_selected(0);
let entry_scroll_state = ScrollbarState::new(entry_table_items.len());
+ let entry_info_scroll_state = ScrollbarState::default();
Self {
entry_table_items,
entry_table_state,
entry_scroll_state,
+ entry_info_scroll: 0,
+ entry_info_scroll_state,
}
}
}
@@ -128,7 +133,9 @@ impl App {
// Movement
pub fn select_next_entry(&mut self) {
- self.scroll_info = 0;
+ self.entry_table.entry_info_scroll = 0;
+ self.entry_table.entry_info_scroll_state =
+ self.entry_table.entry_info_scroll_state.position(0);
self.entry_table.entry_table_state.select_next();
self.entry_table.entry_scroll_state = self
.entry_table
@@ -137,7 +144,9 @@ impl App {
}
pub fn select_previous_entry(&mut self) {
- self.scroll_info = 0;
+ self.entry_table.entry_info_scroll = 0;
+ self.entry_table.entry_info_scroll_state =
+ self.entry_table.entry_info_scroll_state.position(0);
self.entry_table.entry_table_state.select_previous();
self.entry_table.entry_scroll_state = self
.entry_table
@@ -146,13 +155,17 @@ impl App {
}
pub fn select_first_entry(&mut self) {
- self.scroll_info = 0;
+ self.entry_table.entry_info_scroll = 0;
+ self.entry_table.entry_info_scroll_state =
+ self.entry_table.entry_info_scroll_state.position(0);
self.entry_table.entry_table_state.select_first();
self.entry_table.entry_scroll_state = self.entry_table.entry_scroll_state.position(0);
}
pub fn select_last_entry(&mut self) {
- self.scroll_info = 0;
+ self.entry_table.entry_info_scroll = 0;
+ self.entry_table.entry_info_scroll_state =
+ self.entry_table.entry_info_scroll_state.position(0);
self.entry_table.entry_table_state.select_last();
self.entry_table.entry_scroll_state = self
.entry_table
diff --git a/src/frontend/handler.rs b/src/frontend/handler.rs
index ac5b94f..c2cacf5 100644
--- a/src/frontend/handler.rs
+++ b/src/frontend/handler.rs
@@ -48,12 +48,26 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App, tui: &mut Tui) -> R
match app.current_area {
// Keycodes for the tag area
CurrentArea::TagArea => match key_event.code {
- KeyCode::Char('j') | KeyCode::Down => {
+ KeyCode::Down => {
app.select_next_tag();
}
- KeyCode::Char('k') | KeyCode::Up => {
+ KeyCode::Up => {
app.select_previous_tag();
}
+ KeyCode::Char('j') => {
+ if key_event.modifiers == KeyModifiers::ALT {
+ app.scroll_info_down();
+ } else {
+ app.select_next_tag();
+ }
+ }
+ KeyCode::Char('k') => {
+ if key_event.modifiers == KeyModifiers::ALT {
+ app.scroll_info_up();
+ } else {
+ app.select_previous_tag();
+ }
+ }
KeyCode::Char('g') | KeyCode::Home => {
app.select_first_tag();
}
@@ -81,12 +95,26 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App, tui: &mut Tui) -> R
},
// Keycodes for the entry area
CurrentArea::EntryArea => match key_event.code {
- KeyCode::Char('j') | KeyCode::Down => {
+ KeyCode::Down => {
app.select_next_entry();
}
- KeyCode::Char('k') | KeyCode::Up => {
+ KeyCode::Up => {
app.select_previous_entry();
}
+ KeyCode::Char('j') => {
+ if key_event.modifiers == KeyModifiers::ALT {
+ app.scroll_info_down();
+ } else {
+ app.select_next_entry();
+ }
+ }
+ KeyCode::Char('k') => {
+ if key_event.modifiers == KeyModifiers::ALT {
+ app.scroll_info_up();
+ } else {
+ app.select_previous_entry();
+ }
+ }
KeyCode::Char('g') | KeyCode::Home => {
app.select_first_entry();
}
diff --git a/src/frontend/ui.rs b/src/frontend/ui.rs
index 3b79f7a..dfb9017 100644
--- a/src/frontend/ui.rs
+++ b/src/frontend/ui.rs
@@ -17,13 +17,14 @@
use ratatui::{
buffer::Buffer,
- layout::{Constraint, Layout, Rect},
+ layout::{Alignment, Constraint, Layout, Rect},
style::{Color, Modifier, Style, Stylize},
symbols,
text::{Line, Span, Text},
widgets::{
+ block::{Position, Title},
Block, Cell, HighlightSpacing, List, ListItem, Padding, Paragraph, Row, Scrollbar,
- ScrollbarOrientation, StatefulWidget, Table, Widget, Wrap,
+ ScrollbarOrientation, ScrollbarState, StatefulWidget, Table, Widget, Wrap,
},
};
@@ -343,22 +344,32 @@ impl App {
.line_count(area.width);
// Make sure to allow scroll only if text is larger than the rendered area and stop scrolling when last line is reached
let scroll_height = {
- if self.scroll_info == 0 {
- self.scroll_info
+ if self.entry_table.entry_info_scroll == 0 {
+ self.entry_table.entry_info_scroll
} else if area.height > box_height as u16 {
- self.scroll_info = 0;
- self.scroll_info
- } else if self.scroll_info > (box_height as u16 + 1 - area.height) {
- self.scroll_info = box_height as u16 + 1 - area.height;
- self.scroll_info
+ self.entry_table.entry_info_scroll = 0;
+ self.entry_table.entry_info_scroll
+ } else if self.entry_table.entry_info_scroll > (box_height as u16 + 2 - area.height) {
+ self.entry_table.entry_info_scroll = box_height as u16 + 2 - area.height;
+ self.entry_table.entry_info_scroll
} else {
- self.scroll_info
+ self.entry_table.entry_info_scroll
}
};
// We can now render the item info
Paragraph::new(info)
- .block(block)
+ .block(
+ block.title(
+ Title::from(if box_height > area.height.into() {
+ " ▼ "
+ } else {
+ ""
+ })
+ .position(Position::Bottom)
+ .alignment(Alignment::Right),
+ ),
+ )
// .fg(TEXT_FG_COLOR)
.wrap(Wrap { trim: false })
.scroll((scroll_height, 0))
@@ -371,17 +382,19 @@ impl App {
.end_symbol(SCROLLBAR_LOWER_CORNER)
.thumb_style(Style::new().fg(Color::DarkGray));
- if box_height > area.height.into() {
- if let CurrentArea::EntryArea = self.current_area {
- // render the scrollbar
- StatefulWidget::render(
- scrollbar,
- area,
- buf,
- &mut self.entry_table.entry_scroll_state,
- );
- }
- }
+ // if box_height > area.height.into() {
+ // // self.entry_table.entry_info_scroll_state = ScrollbarState::new(area.height.into());
+ // self.entry_table.entry_info_scroll_state = self
+ // .entry_table
+ // .entry_info_scroll_state
+ // .content_length(area.height.into());
+ // StatefulWidget::render(
+ // scrollbar,
+ // area,
+ // buf,
+ // &mut self.entry_table.entry_info_scroll_state,
+ // );
+ // }
}
pub fn render_taglist(&mut self, area: Rect, buf: &mut Buffer) {
@@ -447,12 +460,7 @@ impl App {
if list_length > area.height.into() {
if let CurrentArea::TagArea = self.current_area {
// render the scrollbar
- StatefulWidget::render(
- scrollbar,
- area,
- buf,
- &mut self.entry_table.entry_scroll_state,
- );
+ StatefulWidget::render(scrollbar, area, buf, &mut self.tag_list.tag_scroll_state);
}
}
}