Skip to content

Commit

Permalink
Add swipe sequences for status navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
baskerville committed Feb 16, 2021
1 parent ba588be commit 0e05dad
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
5 changes: 5 additions & 0 deletions doc/MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ This is a view of the books within the current directory.
- Swipe west/east to go to the next/previous page.
- Tap on a book entry to open it.

The following swipe sequences are recognized:

- Arrow west/east: go to the first/last page.
- Top or bottom left/right corner: go to the previous/next status change.

## Search bar

The input's text is interpreted as a regular expression, and a book will match if any of its title, subtitle, author, series or file path matches.
Expand Down
41 changes: 40 additions & 1 deletion src/view/home/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use self::navigation_bar::NavigationBar;
use self::shelf::Shelf;
use self::bottom_bar::BottomBar;
use crate::gesture::GestureEvent;
use crate::geom::{Rectangle, Dir, CycleDir, halves};
use crate::geom::{Rectangle, Dir, DiagDir, CycleDir, halves};
use crate::input::{DeviceEvent, ButtonCode, ButtonStatus};
use crate::device::CURRENT_DEVICE;
use crate::unit::scale_by_dpi;
Expand Down Expand Up @@ -291,6 +291,36 @@ impl Home {
self.update_bottom_bar(rq, context);
}

fn go_to_status_change(&mut self, dir: CycleDir, hub: &Hub, rq: &mut RenderQueue, context: &mut Context) {
if self.pages_count < 2 {
return;
}

let max_lines = self.children[self.shelf_index].as_ref().downcast_ref::<Shelf>().unwrap().max_lines;
let index_lower = self.current_page * max_lines;
let index_upper = (index_lower + max_lines).min(self.visible_books.len());
let book_index = match dir {
CycleDir::Next => index_upper.saturating_sub(1),
CycleDir::Previous => index_lower,
};
let status = self.visible_books[book_index].simple_status();

let page = match dir {
CycleDir::Next => self.visible_books[book_index+1..].iter()
.position(|info| info.simple_status() != status)
.map(|delta| self.current_page + 1 + delta / max_lines),
CycleDir::Previous => self.visible_books[..book_index].iter().rev()
.position(|info| info.simple_status() != status)
.map(|delta| self.current_page - 1 - delta / max_lines),
};

if let Some(page) = page {
self.current_page = page;
self.update_shelf(false, hub, rq, context);
self.update_bottom_bar(rq, context);
}
}

// NOTE: This function assumes that the shelf wasn't resized.
fn refresh_visibles(&mut self, update: bool, reset_page: bool, hub: &Hub, rq: &mut RenderQueue, context: &mut Context) {
let (files, _) = context.library.list(&self.current_directory,
Expand Down Expand Up @@ -1356,6 +1386,15 @@ impl View for Home {
};
true
},
Event::Gesture(GestureEvent::Corner { dir, .. }) => {
match dir {
DiagDir::NorthWest |
DiagDir::SouthWest => self.go_to_status_change(CycleDir::Previous, hub, rq, context),
DiagDir::NorthEast |
DiagDir::SouthEast => self.go_to_status_change(CycleDir::Next, hub, rq, context),
};
true
},
Event::Focus(v) => {
if self.focus != v {
self.focus = v;
Expand Down

0 comments on commit 0e05dad

Please sign in to comment.