E-book viewer: Fix margins not being adjusted immediately when preferences are changed

This commit is contained in:
Kovid Goyal 2021-04-13 10:14:36 +05:30
parent 1fd071971b
commit 5765cd3007
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -152,22 +152,26 @@ def show_controls_help():
# }}} # }}}
def maximum_font_size(): def body_font_size():
ans = maximum_font_size.ans ans = body_font_size.ans
if not ans: if not ans:
q = window.getComputedStyle(document.body).fontSize q = window.getComputedStyle(document.body).fontSize
if q and q.endsWith('px'): if q and q.endsWith('px'):
q = parseInt(q) q = parseInt(q)
if q and not isNaN(q): if q and not isNaN(q):
ans = maximum_font_size.ans = q ans = body_font_size.ans = q
return ans return ans
ans = maximum_font_size.ans = 12 ans = body_font_size.ans = 12
return ans return ans
def header_footer_font_size(sz):
return min(max(0, sz - 6), body_font_size())
def margin_elem(sd, which, id, onclick, oncontextmenu): def margin_elem(sd, which, id, onclick, oncontextmenu):
sz = sd.get(which, 20) sz = sd.get(which, 20)
fsz = min(max(0, sz - 6), maximum_font_size()) fsz = header_footer_font_size(sz)
s = '; text-overflow: ellipsis; white-space: nowrap; overflow: hidden' s = '; text-overflow: ellipsis; white-space: nowrap; overflow: hidden'
ans = E.div( ans = E.div(
style=f'height:{sz}px; overflow: hidden; font-size:{fsz}px; width:100%; padding: 0; display: flex; justify-content: space-between; align-items: center; user-select: none', style=f'height:{sz}px; overflow: hidden; font-size:{fsz}px; width:100%; padding: 0; display: flex; justify-content: space-between; align-items: center; user-select: none',
@ -782,8 +786,8 @@ class View:
extra = (tw - max_text_width) // 2 extra = (tw - max_text_width) // 2
margin_left += extra margin_left += extra
margin_right += extra margin_right += extra
set_css(document.getElementById('book-top-margin'), height=margin_top + 'px') set_css(document.getElementById('book-top-margin'), height=margin_top + 'px', font_size=header_footer_font_size(margin_top) + 'px')
set_css(document.getElementById('book-bottom-margin'), height=margin_bottom + 'px') set_css(document.getElementById('book-bottom-margin'), height=margin_bottom + 'px', font_size=header_footer_font_size(margin_bottom) + 'px')
def side_margin(which, val): def side_margin(which, val):
m = document.getElementById('book-{}-margin'.format(which)) m = document.getElementById('book-{}-margin'.format(which))
if which is 'left': if which is 'left':
@ -969,6 +973,7 @@ class View:
sd.set('controls_help_shown_count' + ('_rtl_page_progression' if rtl_page_progression() else ''), c + 1) sd.set('controls_help_shown_count' + ('_rtl_page_progression' if rtl_page_progression() else ''), c + 1)
def preferences_changed(self): def preferences_changed(self):
self.set_margins()
ui_operations.update_url_state(True) ui_operations.update_url_state(True)
ui_operations.redisplay_book() ui_operations.redisplay_book()