mirror of
https://github.com/koreader/koreader
synced 2024-10-31 21:20:20 +00:00
add reading progress bar at the bottom of ReaderView for pdf/djvu reader
And there is also a toggle full screen option to turn on/off the progress bar.
This commit is contained in:
parent
de65b8934f
commit
c5b4d958bb
@ -38,6 +38,15 @@ KoptOptions = {
|
||||
{
|
||||
icon = "resources/icons/appbar.column.two.large.png",
|
||||
options = {
|
||||
{
|
||||
name = "full_screen",
|
||||
name_text = "Full Screen",
|
||||
toggle = {"on", "off"},
|
||||
values = {1, 0},
|
||||
default_value = 0,
|
||||
event = "SetFullScreen",
|
||||
args = {true, false},
|
||||
},
|
||||
{
|
||||
name = "page_margin",
|
||||
name_text = "Page Margin",
|
||||
|
63
frontend/ui/footer.lua
Normal file
63
frontend/ui/footer.lua
Normal file
@ -0,0 +1,63 @@
|
||||
|
||||
Footer = InputContainer:new{
|
||||
pageno = nil,
|
||||
pages = nil,
|
||||
progress_percentage = 0.0,
|
||||
progress_text = "0 / 0",
|
||||
bar_width = 0.88,
|
||||
text_width = 0.12,
|
||||
text_font_face = "ffont",
|
||||
text_font_size = 14,
|
||||
height = 19,
|
||||
}
|
||||
|
||||
function Footer:init()
|
||||
self.progress_bar = ProgressWidget:new{
|
||||
width = math.floor(Screen:getWidth()*(self.bar_width-0.02)),
|
||||
height = 7,
|
||||
percentage = self.progress_percentage,
|
||||
}
|
||||
self.progress_text = TextWidget:new{
|
||||
text = self.progress_text,
|
||||
face = Font:getFace(self.text_font_face, self.text_font_size),
|
||||
}
|
||||
local _, text_height = self.progress_text:getSize()
|
||||
local horizontal_group = HorizontalGroup:new{}
|
||||
local bar_containner = RightContainer:new{
|
||||
dimen = Geom:new{w = Screen:getWidth()*self.bar_width, h = self.height},
|
||||
self.progress_bar,
|
||||
}
|
||||
local text_containner = CenterContainer:new{
|
||||
dimen = Geom:new{w = Screen:getWidth()*self.text_width, h = self.height},
|
||||
self.progress_text,
|
||||
}
|
||||
table.insert(horizontal_group, bar_containner)
|
||||
table.insert(horizontal_group, text_containner)
|
||||
self[1] = BottomContainer:new{
|
||||
dimen = Screen:getSize(),
|
||||
FrameContainer:new{
|
||||
horizontal_group,
|
||||
background = 0,
|
||||
bordersize = 0,
|
||||
padding = 0,
|
||||
}
|
||||
}
|
||||
self.dimen = self[1]:getSize()
|
||||
self:update()
|
||||
end
|
||||
|
||||
function Footer:paintTo(bb, x, y)
|
||||
self[1]:paintTo(bb, x, y)
|
||||
end
|
||||
|
||||
function Footer:update()
|
||||
self.pageno = self.view.state.page
|
||||
self.pages = self.view.document.info.number_of_pages
|
||||
self.progress_bar.percentage = self.pageno / self.pages
|
||||
self.progress_text.text = string.format("%d / %d", self.pageno, self.pages)
|
||||
end
|
||||
|
||||
function Footer:onPageUpdate(pageno)
|
||||
self.pageno = pageno
|
||||
self:update()
|
||||
end
|
@ -41,9 +41,10 @@ function PageCropDialog:init()
|
||||
table.insert(horizontal_group, HorizontalSpan:new{ width = Screen:getWidth()*0.34})
|
||||
table.insert(horizontal_group, cancel_container)
|
||||
self[2] = FrameContainer:new{
|
||||
horizontal_group,
|
||||
background = 0,
|
||||
bordersize = 0,
|
||||
horizontal_group,
|
||||
padding = 0,
|
||||
}
|
||||
end
|
||||
|
||||
@ -52,6 +53,9 @@ ReaderCropping = InputContainer:new{}
|
||||
function ReaderCropping:onPageCrop(mode)
|
||||
if mode == "auto" then return end
|
||||
self.ui:handleEvent(Event:new("CloseConfig"))
|
||||
-- backup original view dimen
|
||||
self.orig_view_dimen = Geom:new{w = self.view.dimen.w, h = self.view.dimen.h}
|
||||
DEBUG("backup view dimen", self.orig_view_dimen)
|
||||
-- backup original zoom mode as cropping use "page" zoom mode
|
||||
self.orig_zoom_mode = self.view.zoom_mode
|
||||
-- backup original reflow mode as cropping use non-reflow mode
|
||||
@ -64,7 +68,6 @@ function ReaderCropping:onPageCrop(mode)
|
||||
else
|
||||
self.ui:handleEvent(Event:new("SetZoomMode", "page", "cropping"))
|
||||
end
|
||||
self.orig_view_dimen = self.view.dimen:copy()
|
||||
self.ui:handleEvent(Event:new("SetDimensions",
|
||||
Geom:new{w = Screen:getWidth(), h = Screen:getHeight()*11/12})
|
||||
)
|
||||
@ -101,7 +104,7 @@ function ReaderCropping:cancelPageCrop()
|
||||
end
|
||||
|
||||
function ReaderCropping:exitPageCrop(confirmed)
|
||||
self.ui:handleEvent(Event:new("SetDimensions", self.orig_view_dimen))
|
||||
self.ui:handleEvent(Event:new("RestoreDimensions", self.orig_view_dimen))
|
||||
self.document.configurable.text_wrap = self.orig_reflow_mode
|
||||
self.view:recalculate()
|
||||
-- Exiting should have the same look and feel with entering.
|
||||
|
@ -1,3 +1,5 @@
|
||||
require "ui/footer"
|
||||
|
||||
ReaderView = WidgetContainer:new{
|
||||
_name = "ReaderView",
|
||||
document = nil,
|
||||
@ -23,22 +25,36 @@ ReaderView = WidgetContainer:new{
|
||||
page_area = Geom:new{},
|
||||
-- dimen for area to dim
|
||||
dim_area = Geom:new{w = 0, h = 0},
|
||||
-- has footer
|
||||
footer_visible = nil,
|
||||
}
|
||||
|
||||
function ReaderView:resetFooter()
|
||||
if self.footer_visible then
|
||||
self.footer = Footer:new{
|
||||
view = self,
|
||||
}
|
||||
self[1] = self.footer
|
||||
else
|
||||
self.footer = nil
|
||||
self[1] = nil
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderView:paintTo(bb, x, y)
|
||||
DEBUG("painting", self.visible_area, "to", x, y)
|
||||
local inner_offset = Geom:new{x = 0, y = 0}
|
||||
|
||||
-- draw surrounding space, if any
|
||||
if self.ui.dimen.h > self.visible_area.h then
|
||||
inner_offset.y = (self.ui.dimen.h - self.visible_area.h) / 2
|
||||
bb:paintRect(x, y, self.ui.dimen.w, inner_offset.y, self.outer_page_color)
|
||||
bb:paintRect(x, y + self.ui.dimen.h - inner_offset.y - 1, self.ui.dimen.w, inner_offset.y + 1, self.outer_page_color)
|
||||
if self.dimen.h > self.visible_area.h then
|
||||
inner_offset.y = (self.dimen.h - self.visible_area.h) / 2
|
||||
bb:paintRect(x, y, self.dimen.w, inner_offset.y, self.outer_page_color)
|
||||
bb:paintRect(x, y + self.dimen.h - inner_offset.y - 1, self.dimen.w, inner_offset.y + 1, self.outer_page_color)
|
||||
end
|
||||
if self.ui.dimen.w > self.visible_area.w then
|
||||
inner_offset.x = (self.ui.dimen.w - self.visible_area.w) / 2
|
||||
bb:paintRect(x, y, inner_offset.x, self.ui.dimen.h, self.outer_page_color)
|
||||
bb:paintRect(x + self.ui.dimen.w - inner_offset.x - 1, y, inner_offset.x + 1, self.ui.dimen.h, self.outer_page_color)
|
||||
if self.dimen.w > self.visible_area.w then
|
||||
inner_offset.x = (self.dimen.w - self.visible_area.w) / 2
|
||||
bb:paintRect(x, y, inner_offset.x, self.dimen.h, self.outer_page_color)
|
||||
bb:paintRect(x + self.dimen.w - inner_offset.x - 1, y, inner_offset.x + 1, self.dimen.h, self.outer_page_color)
|
||||
end
|
||||
self.state.offset = inner_offset
|
||||
-- draw content
|
||||
@ -79,6 +95,10 @@ function ReaderView:paintTo(bb, x, y)
|
||||
self.dim_area.w, self.dim_area.h
|
||||
)
|
||||
end
|
||||
-- paint footer
|
||||
if self.footer then
|
||||
self.footer:paintTo(bb, x, y)
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
@ -145,6 +165,7 @@ function ReaderView:onSetScreenMode(new_mode)
|
||||
return true
|
||||
end
|
||||
|
||||
-- for returning to FileManager
|
||||
function ReaderView:onRestoreScreenMode(old_mode)
|
||||
if old_mode == "landscape" or old_mode == "portrait" then
|
||||
Screen:setScreenMode(old_mode)
|
||||
@ -154,11 +175,29 @@ function ReaderView:onRestoreScreenMode(old_mode)
|
||||
end
|
||||
|
||||
function ReaderView:onSetDimensions(dimensions)
|
||||
--DEBUG("set dimen", dimensions)
|
||||
self:resetFooter()
|
||||
self.dimen = dimensions
|
||||
if self.footer then
|
||||
self.dimen.h = dimensions.h - self.footer.height
|
||||
end
|
||||
-- recalculate view
|
||||
self:recalculate()
|
||||
end
|
||||
|
||||
function ReaderView:onRestoreDimensions(dimensions)
|
||||
--DEBUG("restore dimen", dimensions)
|
||||
self:resetFooter()
|
||||
self.dimen = dimensions
|
||||
-- recalculate view
|
||||
self:recalculate()
|
||||
end
|
||||
|
||||
function ReaderView:onSetFullScreen(full_screen)
|
||||
self.footer_visible = not full_screen
|
||||
self:onSetDimensions(Screen:getSize())
|
||||
end
|
||||
|
||||
function ReaderView:onReadSettings(config)
|
||||
self.render_mode = config:readSetting("render_mode") or 0
|
||||
local screen_mode = config:readSetting("screen_mode")
|
||||
@ -167,6 +206,14 @@ function ReaderView:onReadSettings(config)
|
||||
self:onSetScreenMode(screen_mode) end)
|
||||
end
|
||||
self.state.gamma = config:readSetting("gamma") or 1.0
|
||||
local full_screen = config:readSetting("kopt_full_screen")
|
||||
if full_screen == nil then
|
||||
self.footer_visible = self.document.info.has_pages
|
||||
self.document.configurable.full_screen = self.footer_visible and 0 or 1
|
||||
else
|
||||
self.footer_visible = full_screen == 0 and true or false
|
||||
end
|
||||
self:resetFooter()
|
||||
end
|
||||
|
||||
function ReaderView:onPageUpdate(new_page_no)
|
||||
|
@ -111,10 +111,10 @@ function ToggleSwitch:togglePosition(position)
|
||||
end
|
||||
|
||||
function ToggleSwitch:onTapSelect(arg, gev)
|
||||
DEBUG("toggle position:", position)
|
||||
local position = math.ceil(
|
||||
(gev.pos.x - self.dimen.x) / self.dimen.w * self.n_pos
|
||||
)
|
||||
--DEBUG("toggle position:", position)
|
||||
self:togglePosition(position)
|
||||
local option_value = nil
|
||||
local option_arg = nil
|
||||
|
Loading…
Reference in New Issue
Block a user