Viewer: Fix viewer flickering when scrollbar is enabled and the header/footer is too wide for the screen.

This commit is contained in:
Kovid Goyal 2019-11-10 23:28:50 +05:30
parent b1dbedaab0
commit bc0c9c1fcc
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 12 additions and 4 deletions

View File

@ -9,6 +9,9 @@ from book_list.theme import cached_color_to_rgba
from dom import unique_id from dom import unique_id
SIZE = 10
class BookScrollbar: class BookScrollbar:
def __init__(self, view): def __init__(self, view):
@ -27,10 +30,10 @@ class BookScrollbar:
self.on_bob_mouseup = self.on_bob_mouse_event.bind(None, 'up') self.on_bob_mouseup = self.on_bob_mouse_event.bind(None, 'up')
return E.div( return E.div(
id=self.container_id, id=self.container_id,
style='height: 100vh; background-color: #aaa; width: 10px; border-radius: 5px', style=f'height: 100vh; background-color: #aaa; width: {SIZE}px; border-radius: 5px',
onclick=self.bar_clicked, onclick=self.bar_clicked,
E.div( E.div(
style='position: relative; width: 100%; height: 22px; background-color: #444; border-radius: 5px', style=f'position: relative; width: 100%; height: {int(2.2*SIZE)}px; background-color: #444; border-radius: 5px',
onmousedown=self.on_bob_mousedown, onmousedown=self.on_bob_mousedown,
), ),
E.div( E.div(
@ -82,6 +85,10 @@ class BookScrollbar:
sd = get_session_data() sd = get_session_data()
self.container.style.display = 'block' if sd.get('book_scrollbar') else 'none' self.container.style.display = 'block' if sd.get('book_scrollbar') else 'none'
@property
def effective_width(self):
return SIZE if self.container.style.display is 'block' else 0
def set_position(self, frac): def set_position(self, frac):
c = self.container c = self.container
frac = max(0, min(frac, 1)) frac = max(0, min(frac, 1))

View File

@ -507,8 +507,9 @@ class View:
if which is 'left': if which is 'left':
# Explicitly set the width of the central panel. This is needed # Explicitly set the width of the central panel. This is needed
# on small screens with chrome, without it sometimes the right # on small screens with chrome, without it sometimes the right
# margin goes off the screen. # margin/scrollbar goes off the screen.
m.nextSibling.style.maxWidth = 'calc(100vw - {}px)'.format(margin_left + margin_right) m.nextSibling.style.maxWidth = 'calc(100vw - {}px)'.format(
margin_left + margin_right + self.book_scrollbar.effective_width)
set_css(m, width=val + 'px') set_css(m, width=val + 'px')
val = min(val, 25) val = min(val, 25)
m.firstChild.style.width = val + 'px' m.firstChild.style.width = val + 'px'