UI for changing font size

This commit is contained in:
Kovid Goyal 2016-09-27 08:12:08 +05:30
parent 6f016b7b38
commit 28f8b0aa7b
3 changed files with 41 additions and 5 deletions

View File

@ -259,7 +259,7 @@ class FontSizeOverlay:
self.overlay = overlay self.overlay = overlay
def show(self, container): def show(self, container):
create_font_size_panel(container) create_font_size_panel(container, self.overlay.hide_current_panel)
class Overlay: class Overlay:

View File

@ -2,12 +2,45 @@
# 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 hash_literals, bound_methods from __python__ import hash_literals, bound_methods
from dom import unique_id, set_css, add_extra_css, build_rule
from elementmaker import E from elementmaker import E
from book_list.globals import get_session_data, get_boss
from book_list.theme import get_color
def create_font_size_panel(container): CONTAINER = unique_id('font-size-prefs')
container.appendChild(E.div( QUICK = unique_id('quick')
style='margin:15vh auto; max-width: 500px; border-radius: 8px; border: solid 1px currentColor',
add_extra_css(def():
style = build_rule('#' + QUICK + ' li.current', background_color=get_color('window-background2'))
style += build_rule('#' + QUICK + ' li:hover', background_color=get_color('window-background2'))
return style
)
def change_font_size(sz):
sd = get_session_data()
if sd.get('base_font_size') is not sz:
sd.set('base_font_size', sz)
get_boss().read_ui.update_font_size()
def set_quick_size(ev):
li = ev.currentTarget
sz = int(li.dataset.sz)
change_font_size(sz)
def create_font_size_panel(container, close):
container.appendChild(E.div(id=CONTAINER,
style='margin:15vh auto; max-width: 500px; border-radius: 8px; border: solid 1px currentColor; padding:1ex 1rem',
onclick=def(ev): ev.preventDefault(), ev.stopPropagation onclick=def(ev): ev.preventDefault(), ev.stopPropagation
)) ))
container = container.lastChild
container.style.backgroundColor = get_color('window-background')
quick = E.ul(id=QUICK, style='display:flex; justify-content:space-around; flex-wrap: wrap; align-items: baseline; list-style: none')
container.appendChild(quick)
sd = get_session_data()
cfs = sd.get('base_font_size')
for sz in (10, 12, 14, 16, 18, 20, 22):
quick.appendChild(set_css(E.li('Aa', title='{} px'.format(sz), class_='current' if cfs is sz else '', data_sz=str(sz), onclick=def(ev):set_quick_size(ev), close();),
display='inline-block', font_size=sz + 'px', padding='5px', cursor='pointer', border_radius='2px'))
develop = create_font_size_panel def develop(container):
create_font_size_panel(container, def():pass;)

View File

@ -110,6 +110,9 @@ class ReadUI:
def redisplay_book(self): def redisplay_book(self):
self.view.redisplay_book() self.view.redisplay_book()
def update_font_size(self):
self.view.update_font_size()
@property @property
def url_data(self): def url_data(self):
ans = {'book_id':self.base_url_data.book_id, 'fmt': self.base_url_data.fmt} ans = {'book_id':self.base_url_data.book_id, 'fmt': self.base_url_data.fmt}