mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-04 19:43:37 +02:00
Implement swipe up/down gestures tto move between sections
This commit is contained in:
parent
805ff687dd
commit
8169ad1f7a
3 changed files with 15 additions and 1 deletions
|
|
@ -25,6 +25,13 @@ def create_goto_list(onclick):
|
|||
return ans
|
||||
|
||||
|
||||
def get_next_section(forward):
|
||||
toc = current_book().manifest.toc
|
||||
id_map = get_toc_maps(toc)[1]
|
||||
before, after = get_border_nodes(toc, id_map)
|
||||
return after if forward else before
|
||||
|
||||
|
||||
def create_goto_panel(book, container, onclick):
|
||||
panel = create_goto_list(onclick)
|
||||
set_css(container, display='flex', flex_direction='column')
|
||||
|
|
|
|||
|
|
@ -505,7 +505,7 @@ def onkeydown(evt):
|
|||
def handle_gesture(gesture):
|
||||
if gesture.type is 'swipe':
|
||||
if gesture.axis is 'vertical':
|
||||
pass # TODO: next/prev section
|
||||
get_boss().send_message('next_section', forward=gesture.direction is 'up')
|
||||
else:
|
||||
if not gesture.active or gesture.is_held:
|
||||
scroll_by_page(gesture.direction is 'right', True)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
from read_book.prefs.font_size import change_font_size_by
|
||||
from read_book.touch import set_left_margin_handler, set_right_margin_handler
|
||||
from read_book.toc import update_visible_toc_nodes
|
||||
from read_book.goto import get_next_section
|
||||
from book_list.theme import get_color
|
||||
from utils import parse_url_params, username_key
|
||||
|
||||
|
|
@ -82,6 +83,7 @@ def __init__(self, container, ui):
|
|||
'ready': self.on_iframe_ready,
|
||||
'error': self.on_iframe_error,
|
||||
'next_spine_item': self.on_next_spine_item,
|
||||
'next_section': self.on_next_section,
|
||||
'goto_doc_boundary': self.goto_doc_boundary,
|
||||
'scroll_to_anchor': self.on_scroll_to_anchor,
|
||||
'update_cfi': self.on_update_cfi,
|
||||
|
|
@ -310,6 +312,11 @@ def on_next_spine_item(self, data):
|
|||
idx = max(0, min(spine.length - 1, idx + 1))
|
||||
self.show_name(spine[idx], initial_position={'type':'frac', 'frac':0, 'replace_history':True})
|
||||
|
||||
def on_next_section(self, data):
|
||||
toc_node = get_next_section(data.forward)
|
||||
if toc_node:
|
||||
self.goto_named_destination(toc_node.dest, toc_node.frag)
|
||||
|
||||
def on_update_cfi(self, data):
|
||||
self.currently_showing.bookpos = data.cfi
|
||||
get_boss().push_state(replace=data.replace_history)
|
||||
|
|
|
|||
Loading…
Reference in a new issue