Viewer: use an inch as the limit for the back tap zone rather than 100px

This commit is contained in:
Kovid Goyal 2023-01-31 19:59:35 +05:30
parent 31b0c321fc
commit 5e758211f1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 23 additions and 11 deletions

View File

@ -2,9 +2,9 @@
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
from __python__ import bound_methods, hash_literals
from read_book.globals import get_boss, ui_operations, ltr_page_progression
from read_book.viewport import scroll_viewport
from read_book.globals import get_boss, ltr_page_progression, ui_operations
from read_book.settings import opts
from read_book.viewport import get_unit_size_in_pixels, scroll_viewport
HOLD_THRESHOLD = 750 # milliseconds
TAP_THRESHOLD = 8 # pixels
@ -233,6 +233,13 @@ class TouchHandler:
return
self.handle_gesture(gesture)
def inch_in_pixels():
ans = inch_in_pixels().ans
if not ans:
ans = inch_in_pixels.ans = max(2, get_unit_size_in_pixels('in'))
return ans
class BookTouchHandler(TouchHandler):
def __init__(self, for_side_margin=None):
@ -250,21 +257,23 @@ class BookTouchHandler(TouchHandler):
return
if not gesture.active:
if self.for_side_margin or not tap_on_link(gesture):
inch = inch_in_pixels()
if gesture.viewport_y < min(100, scroll_viewport.height() / 4):
gesture.type = 'show-chrome'
else:
limit = inch
# default, books that go left to right.
if ltr_page_progression() and not opts.reverse_page_turn_zones:
if gesture.viewport_x < min(100, scroll_viewport.width() / 4):
if gesture.viewport_x < min(limit, scroll_viewport.width() / 4):
gesture.type = 'prev-page'
else:
gesture.type = 'next-page'
# We swap the sizes in RTL mode, so that going to the next page is always the bigger touch region.
else:
# The "going back" area should not be more than 100 units big,
# even if 1/4 of the scroll viewport is more than 100 units.
# Checking against the larger of the width minus the 100 units and 3/4 of the width will accomplish that.
if gesture.viewport_x > max(scroll_viewport.width() - 100, scroll_viewport.width() * (3/4)):
# The "going back" area should not be more than limit units big,
# even if 1/4 of the scroll viewport is more than limit units.
# Checking against the larger of the width minus the limit units and 3/4 of the width will accomplish that.
if gesture.viewport_x > max(scroll_viewport.width() - limit, scroll_viewport.width() * (3/4)):
gesture.type = 'prev-page'
else:
gesture.type = 'next-page'

View File

@ -116,12 +116,15 @@ def show_controls_help():
return set_css(E.div(txt), padding='1ex 1em', text_align='center', margin='auto')
left_msg = msg(_('Tap to turn back'))
left_width = '25vw'
left_width = 'min(25vw, 1in)'
right_msg = msg(_('Tap to turn page'))
right_width = '75vw'
right_width = 'auto'
left_grow = 0
right_grow = 1
if rtl_page_progression():
left_msg, right_msg = right_msg, left_msg
left_width, right_width = right_width, left_width
left_grow, right_grow = right_grow, left_grow
# Clear it out if this is not the first time it's created.
# Needed to correctly show it again in a different page progression direction.
@ -139,11 +142,11 @@ def show_controls_help():
style="display: flex; align-items: stretch; flex-grow: 10",
E.div(
left_msg,
style=f'width: {left_width}; display:flex; align-items: center; border-right: solid 2px currentColor',
style=f'width: {left_width}; flex-grow: {left_grow}; display:flex; align-items: center; border-right: solid 2px currentColor',
),
E.div(
right_msg,
style=f'width: {right_width}; display:flex; align-items: center',
style=f'width: {right_width}; display:flex; flex-grow: {right_grow}; align-items: center',
)
)
))