mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Make the number of columns per screen automatic in paged mode
This commit is contained in:
parent
1cc40a335e
commit
c3b015e75e
@ -106,14 +106,19 @@ def layout(is_single_page):
|
||||
nonlocal _in_paged_mode, col_width, col_and_gap, screen_height, gap, screen_width, is_full_screen_layout, cols_per_screen
|
||||
body_style = window.getComputedStyle(document.body)
|
||||
first_layout = not _in_paged_mode
|
||||
cps = opts.columns_per_screen
|
||||
cps = cps.landscape if window.innerWidth > window.innerHeight else cps.portrait
|
||||
if cps is 'auto':
|
||||
cps = int(Math.floor(window.innerWidth / 500.0))
|
||||
cps = max(1, min(cps or 1, 20))
|
||||
if first_layout:
|
||||
handle_rtl_body(body_style)
|
||||
# Check if the current document is a full screen layout like
|
||||
# cover, if so we treat it specially.
|
||||
single_screen = (document.body.scrollHeight < window.innerHeight + 75)
|
||||
first_layout = True
|
||||
if not single_screen and opts.cols_per_screen > 1:
|
||||
num = opts.cols_per_screen - 1
|
||||
if not single_screen and cps > 1:
|
||||
num = cps - 1
|
||||
elems = document.querySelectorAll('body > *')
|
||||
if elems.length == 1:
|
||||
# Workaround for the case when the content is wrapped in a
|
||||
@ -125,7 +130,7 @@ def layout(is_single_page):
|
||||
num -= 1
|
||||
create_page_div()
|
||||
|
||||
n = cols_per_screen = opts.cols_per_screen
|
||||
n = cols_per_screen = cps
|
||||
# Calculate the column width so that cols_per_screen columns fit exactly in
|
||||
# the window width, with their separator margins
|
||||
ww = col_width = screen_width = window.innerWidth
|
||||
|
@ -6,7 +6,7 @@ opts = {}
|
||||
|
||||
def apply_settings(settings):
|
||||
settings = settings or {}
|
||||
opts.cols_per_screen = max(1, settings.cols_per_screen or 1)
|
||||
opts.columns_per_screen = settings.columns_per_screen or {'portrait':'auto', 'landscape':'auto'}
|
||||
opts.margin_left = max(0, settings.margin_left or 0)
|
||||
opts.margin_right = max(0, settings.margin_right or 0)
|
||||
opts.color_scheme = settings.color_scheme
|
||||
|
@ -102,7 +102,8 @@ class View:
|
||||
def show_chrome(self):
|
||||
self.overlay.show()
|
||||
|
||||
def set_margins(self, no_margins):
|
||||
def set_margins(self):
|
||||
no_margins = self.currently_showing.name is self.book.manifest.title_page_name
|
||||
sd = get_session_data()
|
||||
margin_left = 0 if no_margins else sd.get('margin_left')
|
||||
margin_right = 0 if no_margins else sd.get('margin_right')
|
||||
@ -197,7 +198,7 @@ class View:
|
||||
return ans
|
||||
|
||||
def on_resize(self):
|
||||
pass
|
||||
self.set_margins() # needed because of max text height/width
|
||||
|
||||
def show_loading(self):
|
||||
title = self.book.metadata.title
|
||||
@ -244,7 +245,7 @@ class View:
|
||||
'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'),
|
||||
'cols_per_screen': sd.get('cols_per_screen'),
|
||||
'columns_per_screen': sd.get('columns_per_screen'),
|
||||
'color_scheme': self.get_color_scheme(True),
|
||||
}
|
||||
initial_position = initial_position or {'replace_history':False}
|
||||
@ -254,7 +255,7 @@ class View:
|
||||
idx = spine.indexOf(name)
|
||||
if idx > -1:
|
||||
self.currently_showing.bookpos = 'epubcfi(/{})'.format(2 * (idx +1))
|
||||
self.set_margins(name is self.book.manifest.title_page_name)
|
||||
self.set_margins()
|
||||
load_resources(self.ui.db, self.book, name, self.loaded_resources, self.show_spine_item)
|
||||
|
||||
def goto_doc_boundary(self, data):
|
||||
|
@ -25,7 +25,7 @@ defaults = {
|
||||
'read_mode': 'paged',
|
||||
'max_text_height': 0,
|
||||
'max_text_width': 0,
|
||||
'cols_per_screen': 1,
|
||||
'columns_per_screen': {'portrait':'auto', 'landscape':'auto'},
|
||||
'current_color_scheme': 'white',
|
||||
'user_color_schemes': {},
|
||||
}
|
||||
@ -38,7 +38,7 @@ is_local_setting = {
|
||||
'read_mode': 'paged',
|
||||
'max_text_height': True,
|
||||
'max_text_width': True,
|
||||
'cols_per_screen': True,
|
||||
'columns_per_screen': True,
|
||||
'current_color_scheme': True,
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user