Margins for the reader

This commit is contained in:
Kovid Goyal 2016-04-09 17:27:07 +05:30
parent 25b631efad
commit 37b7ab4a13
2 changed files with 26 additions and 2 deletions

View File

@ -2,6 +2,7 @@
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net> # License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
from __python__ import bound_methods from __python__ import bound_methods
from book_list.globals import get_session_data
from elementmaker import E from elementmaker import E
from gettext import gettext as _ from gettext import gettext as _
from read_book.globals import messenger, iframe_id from read_book.globals import messenger, iframe_id
@ -30,12 +31,19 @@ class View:
def __init__(self, container, ui): def __init__(self, container, ui):
self.ui = ui self.ui = ui
self.loaded_resources = {} self.loaded_resources = {}
sd = get_session_data()
container.appendChild( container.appendChild(
E.div(style='width: 100vw; height: 100vh; overflow: hidden; display: flex; align-items: stretch', # container for horizontally aligned panels 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='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='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_side', 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%'.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.iframe(id=iframe_id, seamless=True, sandbox='allow-popups allow-scripts', style='flex-grow: 2'),
E.div(style='position: absolute; top:0; left:0; width: 100%; height: 100%; display:none'), # overlay container E.div(style='height:{}px; width:100%'.format(sd.get('margin_bottom', 20)), id='book-bottom-margin'),
),
E.div(style='width:{}px; height:100%'.format(sd.get('margin_side', 20)), id='book-right-margin'),
E.div(style='position: absolute; top:0; left:0; width: 100%; height: 100%; display:none', id='book-overlay'), # overlay
) )
) )
) )
@ -59,6 +67,16 @@ class View:
def iframe(self): def iframe(self):
return document.getElementById(iframe_id) return document.getElementById(iframe_id)
def set_margins(self, margin_side=None, margin_top=None, margin_bottom=None):
sd = get_session_data()
margin_side = sd.get('margin_side') if margin_side is None else margin_side
margin_top = sd.get('margin_top') if margin_top is None else margin_top
margin_bottom = sd.get('margin_bottom') if margin_bottom is None else margin_bottom
document.getElementById('book-left-margin').style.width = margin_side + 'px'
document.getElementById('book-right-margin').style.width = margin_side + 'px'
document.getElementById('book-top-margin').style.height = margin_top + 'px'
document.getElementById('book-bottom-margin').style.height = margin_bottom + 'px'
def create_src_doc(self): 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') iframe_script = self.ui.interface_data.main_js.replace(/is_running_in_iframe\s*=\s*false/, 'is_running_in_iframe = true')
self.ui.interface_data.main_js = None self.ui.interface_data.main_js = None
@ -122,6 +140,7 @@ class View:
if self.currently_showing.loading: if self.currently_showing.loading:
return return
self.currently_showing = {'name':name, 'cfi':cfi, 'initial_scroll_fraction':initial_scroll_fraction, 'loading':True} self.currently_showing = {'name':name, 'cfi':cfi, 'initial_scroll_fraction':initial_scroll_fraction, 'loading':True}
self.set_margins(0, 0, 0) if name is self.book.manifest.title_page_name else self.set_margins()
load_resources(self.ui.db, self.book, name, self.loaded_resources, self.show_spine_item) load_resources(self.ui.db, self.book, name, self.loaded_resources, self.show_spine_item)
def goto_doc_boundary(self, data): def goto_doc_boundary(self, data):

View File

@ -15,6 +15,11 @@ defaults = {
'sort_tags_by': 'name', # other choices: popularity, rating 'sort_tags_by': 'name', # other choices: popularity, rating
'hide_empty_categories': 'no', 'hide_empty_categories': 'no',
'and_search_terms': False, # how to add search terms to the search expression from the Tag Browser 'and_search_terms': False, # how to add search terms to the search expression from the Tag Browser
# Book reader settings
'margin_side': 20,
'margin_top': 20,
'margin_bottom': 20,
} }
def storage_available(which): def storage_available(which):