Side margins in paged mode

This commit is contained in:
Kovid Goyal 2016-04-30 10:55:06 +05:30
parent 45853001cb
commit 5f3de701d4
5 changed files with 29 additions and 26 deletions

View File

@ -6,7 +6,6 @@ from dom import set_css
from read_book.globals import get_boss
from keycodes import get_key
from utils import document_height, document_width
from read_book.settings import opts
def flow_to_scroll_fraction(frac):
window.scrollTo(0, document_height() * frac)
@ -98,9 +97,5 @@ def flow_onkeydown(evt):
evt.preventDefault()
def layout(is_single_page):
ms = opts.margin_side
tw = window.innerWidth - 2 * ms
if opts.max_text_width > 100 and tw > opts.max_text_width:
ms += (tw - opts.max_text_width) // 2
set_css(document.body, margin='0', border_width='0', padding='0 {}px'.format(ms))
set_css(document.body, margin='0', border_width='0', padding='0')

View File

@ -126,8 +126,8 @@ def layout(is_single_page):
if n > 1:
# Adjust the side margin so that the window width satisfies
# col_width * n + (n-1) * 2 * side_margin = window_width
sm = opts.margin_side or 0
gap = 2*sm + ((ww + 2*sm) % n) # Ensure ww + gap is a multiple of n
sm = opts.margin_left + opts.margin_right
gap = sm + ((ww + sm) % n) # Ensure ww + gap is a multiple of n
col_width = ((ww + gap) // n) - gap
screen_height = window.innerHeight

View File

@ -7,9 +7,7 @@ opts = {}
def apply_settings(settings):
settings = settings or {}
opts.cols_per_screen = max(1, settings.cols_per_screen or 1)
opts.max_text_width = max(0, settings.max_text_width or 0)
opts.max_text_height = max(0, settings.max_text_height or 0)
opts.fit_images = False if settings.fit_images is False else True
opts.margin_side = max(0, settings.margin_side or 0)
opts.margin_left = max(0, settings.margin_left or 0)
opts.margin_right = max(0, settings.margin_right or 0)
apply_settings()

View File

@ -3,6 +3,7 @@
from __python__ import bound_methods, hash_literals
from book_list.globals import get_session_data
from dom import set_css
from elementmaker import E
from gettext import gettext as _
from read_book.globals import messenger, iframe_id
@ -36,11 +37,13 @@ class View:
E.div(style='width: 100vw; height: 100vh; overflow: hidden; display: flex; align-items: stretch', # container for horizontally aligned panels
E.div(style='display: flex; flex-direction: column; align-items: stretch; flex-grow:2', # container for iframe and any other panels in the same column
E.div(style='flex-grow: 2; display:flex; align-items: stretch', # container for iframe and its overlay
E.div(style='width:{}px; height:100%'.format(sd.get('margin_left', 20)), id='book-left-margin'),
E.div(style='flex-grow:2; display:flex; align-items:stretch; flex-direction: column', # container for top and bottom margins
E.div(style='height:{}px; width:100%; padding: 0 {}px'.format(sd.get('margin_top', 20), sd.get('margin_side', 20)), id='book-top-margin'),
E.div(style='height:{}px; width:100%; padding: 0'.format(sd.get('margin_top', 20)), id='book-top-margin'),
E.iframe(id=iframe_id, seamless=True, sandbox='allow-popups allow-scripts', style='flex-grow: 2'),
E.div(style='height:{}px; width:100%; padding: 0 {}px'.format(sd.get('margin_top', 20), sd.get('margin_side', 20)), id='book-bottom-margin'),
E.div(style='height:{}px; width:100%; padding: 0'.format(sd.get('margin_bottom', 20)), id='book-bottom-margin'),
),
E.div(style='width:{}px; height:100%'.format(sd.get('margin_right', 20)), id='book-right-margin'),
E.div(style='position: absolute; top:0; left:0; width: 100%; height: 100%; display:none', id='book-overlay'), # overlay
)
)
@ -67,21 +70,26 @@ class View:
def set_margins(self, no_margins):
sd = get_session_data()
margin_side = 0 if no_margins else sd.get('margin_side')
margin_left = 0 if no_margins else sd.get('margin_left')
margin_right = 0 if no_margins else sd.get('margin_right')
margin_top = 0 if no_margins else sd.get('margin_top')
margin_bottom = 0 if no_margins else sd.get('margin_bottom')
max_text_height = sd.get('max_text_height')
th = window.innerWidth - margin_top - margin_bottom
th = window.innerHeight - margin_top - margin_bottom
if not no_margins and max_text_height > 100 and th > max_text_height:
extra = (th - max_text_height) // 2
margin_top += extra
margin_bottom += extra
t = document.getElementById('book-top-margin')
t.style.height = margin_top + 'px'
t.style.paddingLeft = t.style.paddingRight = margin_side + 'px'
b = document.getElementById('book-bottom-margin')
b.style.height = margin_bottom + 'px'
b.style.paddingLeft = b.style.paddingRight = margin_side + 'px'
max_text_width = sd.get('max_text_width')
tw = window.innerWidth - margin_left - margin_right
if not no_margins and max_text_width > 100 and tw > max_text_width:
extra = (tw - max_text_width) // 2
margin_left += extra
margin_right += extra
set_css(document.getElementById('book-top-margin'), height=margin_top + 'px')
set_css(document.getElementById('book-bottom-margin'), height=margin_bottom + 'px')
set_css(document.getElementById('book-left-margin'), width=margin_left + 'px')
set_css(document.getElementById('book-right-margin'), width=margin_right + 'px')
def create_src_doc(self):
iframe_script = self.ui.interface_data.main_js.replace(/is_running_in_iframe\s*=\s*false/, 'is_running_in_iframe = true')
@ -147,10 +155,10 @@ class View:
return
sd = get_session_data()
settings={
'margin_side': 0 if name is self.book.manifest.title_page_name else sd.get('margin_side'),
'margin_left': 0 if name is self.book.manifest.title_page_name else sd.get('margin_left'),
'margin_right': 0 if name is self.book.manifest.title_page_name else sd.get('margin_right'),
'read_mode': sd.get('read_mode'),
'max_text_width':sd.get('max_text_width'),
'max_text_height':sd.get('max_text_height'),
'cols_per_screen': sd.get('cols_per_screen'),
}
self.currently_showing = {'name':name, 'cfi':cfi, 'settings':settings, 'initial_scroll_fraction':initial_scroll_fraction, 'loading':True}
self.set_margins(name is self.book.manifest.title_page_name)

View File

@ -18,12 +18,14 @@ defaults = {
'and_search_terms': False, # how to add search terms to the search expression from the Tag Browser
# Book reader settings
'margin_side': 20,
'margin_right': 20,
'margin_left': 20,
'margin_top': 20,
'margin_bottom': 20,
'read_mode': 'paged',
'max_text_height': 0,
'max_text_width': 0,
'cols_per_screen': 1,
}
def storage_available(which):