Browser viewer: Fix controls help overlay not being displayed the first time the viewer is used

This commit is contained in:
Kovid Goyal 2017-08-14 09:36:31 +05:30
parent 1fb6bd16ca
commit cf824e5670
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 36 additions and 38 deletions

View File

@ -282,39 +282,6 @@ class MainOverlay:
# }}}
# ControlsOverlay {{{
class ControlsOverlay:
def __init__(self, overlay):
self.overlay = overlay
def show(self, container):
self.container_id = container.getAttribute('id')
def msg(txt):
return set_css(E.div(txt), padding='1ex 1em', text_align='center', margin='auto')
container.appendChild(E.div(
style=f'overflow: hidden; width: 100vw; height: 100vh; text-align: center; font-size: 1.3rem; font-weight: bold; background: {get_color("window-background")};' +
'display:flex; flex-direction: column; align-items: stretch',
E.div(
msg(_('Tap (or right click) for controls')),
style='height: 25vh; display:flex; align-items: center; border-bottom: solid 2px currentColor',
),
E.div(
style="display: flex; align-items: stretch; flex-grow: 10",
E.div(
msg(_('Tap to turn back')),
style='width: 25vw; display:flex; align-items: center; border-right: solid 2px currentColor',
),
E.div(
msg(_('Tap to turn page')),
style='width: 75vw; display:flex; align-items: center',
)
)
))
# }}}
class TOCOverlay: # {{{
def __init__(self, overlay, create_func, title):
@ -413,10 +380,6 @@ class Overlay:
self.panels = [p for p in self.panels if not isinstance(p, LoadingMessage)]
self.show_current_panel()
def show_controls_help(self):
self.panels.push(ControlsOverlay(self))
self.show_current_panel()
def hide_current_panel(self):
p = self.panels.pop()
if p and callable(p.on_hide):

View File

@ -52,6 +52,40 @@ add_extra_css(def():
)
# ControlsOverlay {{{
def show_controls_help():
container = document.getElementById('controls-help-overlay')
container.style.display = 'block'
if not show_controls_help.listener_added:
show_controls_help.listener_added = True
container.addEventListener('click', def():
document.getElementById('controls-help-overlay').style.display = 'none'
)
def msg(txt):
return set_css(E.div(txt), padding='1ex 1em', text_align='center', margin='auto')
container.appendChild(E.div(
style=f'overflow: hidden; width: 100vw; height: 100vh; text-align: center; font-size: 1.3rem; font-weight: bold; background: {get_color("window-background")};' +
'display:flex; flex-direction: column; align-items: stretch',
E.div(
msg(_('Tap (or right click) for controls')),
style='height: 25vh; display:flex; align-items: center; border-bottom: solid 2px currentColor',
),
E.div(
style="display: flex; align-items: stretch; flex-grow: 10",
E.div(
msg(_('Tap to turn back')),
style='width: 25vw; display:flex; align-items: center; border-right: solid 2px currentColor',
),
E.div(
msg(_('Tap to turn page')),
style='width: 75vw; display:flex; align-items: center',
)
)
))
# }}}
def margin_elem(sd, which, id, onclick):
sz = sd.get(which, 20)
fsz = min(max(0, sz - 6), 12)
@ -94,6 +128,7 @@ class View:
right_margin,
E.div(style='position: absolute; top:0; left:0; width: 100%; pointer-events:none; display:none', id='book-search-overlay'), # search overlay
E.div(style='position: absolute; top:0; left:0; width: 100%; height: 100%; display:none', id='book-overlay'), # main overlay
E.div(style='position: absolute; top:0; left:0; width: 100%; height: 100%; display:none', id='controls-help-overlay'), # controls help overlay
)
)
)
@ -355,7 +390,7 @@ class View:
sd = get_session_data()
c = sd.get('controls_help_shown_count', 0)
if c < 1:
self.overlay.show_controls_help()
show_controls_help()
sd.set('controls_help_shown_count', c + 1)
def redisplay_book(self):