mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Implement swipe up/down gestures tto move between sections
This commit is contained in:
parent
805ff687dd
commit
8169ad1f7a
@ -25,6 +25,13 @@ def create_goto_list(onclick):
|
|||||||
return ans
|
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):
|
def create_goto_panel(book, container, onclick):
|
||||||
panel = create_goto_list(onclick)
|
panel = create_goto_list(onclick)
|
||||||
set_css(container, display='flex', flex_direction='column')
|
set_css(container, display='flex', flex_direction='column')
|
||||||
|
@ -505,7 +505,7 @@ def onkeydown(evt):
|
|||||||
def handle_gesture(gesture):
|
def handle_gesture(gesture):
|
||||||
if gesture.type is 'swipe':
|
if gesture.type is 'swipe':
|
||||||
if gesture.axis is 'vertical':
|
if gesture.axis is 'vertical':
|
||||||
pass # TODO: next/prev section
|
get_boss().send_message('next_section', forward=gesture.direction is 'up')
|
||||||
else:
|
else:
|
||||||
if not gesture.active or gesture.is_held:
|
if not gesture.active or gesture.is_held:
|
||||||
scroll_by_page(gesture.direction is 'right', True)
|
scroll_by_page(gesture.direction is 'right', True)
|
||||||
|
@ -15,6 +15,7 @@ from read_book.prefs.colors import resolve_color_scheme
|
|||||||
from read_book.prefs.font_size import change_font_size_by
|
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.touch import set_left_margin_handler, set_right_margin_handler
|
||||||
from read_book.toc import update_visible_toc_nodes
|
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 book_list.theme import get_color
|
||||||
from utils import parse_url_params, username_key
|
from utils import parse_url_params, username_key
|
||||||
|
|
||||||
@ -82,6 +83,7 @@ class View:
|
|||||||
'ready': self.on_iframe_ready,
|
'ready': self.on_iframe_ready,
|
||||||
'error': self.on_iframe_error,
|
'error': self.on_iframe_error,
|
||||||
'next_spine_item': self.on_next_spine_item,
|
'next_spine_item': self.on_next_spine_item,
|
||||||
|
'next_section': self.on_next_section,
|
||||||
'goto_doc_boundary': self.goto_doc_boundary,
|
'goto_doc_boundary': self.goto_doc_boundary,
|
||||||
'scroll_to_anchor': self.on_scroll_to_anchor,
|
'scroll_to_anchor': self.on_scroll_to_anchor,
|
||||||
'update_cfi': self.on_update_cfi,
|
'update_cfi': self.on_update_cfi,
|
||||||
@ -310,6 +312,11 @@ class View:
|
|||||||
idx = max(0, min(spine.length - 1, idx + 1))
|
idx = max(0, min(spine.length - 1, idx + 1))
|
||||||
self.show_name(spine[idx], initial_position={'type':'frac', 'frac':0, 'replace_history':True})
|
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):
|
def on_update_cfi(self, data):
|
||||||
self.currently_showing.bookpos = data.cfi
|
self.currently_showing.bookpos = data.cfi
|
||||||
get_boss().push_state(replace=data.replace_history)
|
get_boss().push_state(replace=data.replace_history)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user