diff --git a/frontend/apps/reader/modules/readerfooter.lua b/frontend/apps/reader/modules/readerfooter.lua index 60a201597..4ab014590 100644 --- a/frontend/apps/reader/modules/readerfooter.lua +++ b/frontend/apps/reader/modules/readerfooter.lua @@ -87,7 +87,7 @@ local footerTextGeneratorMap = { end, } -local ReaderFooter = WidgetContainer:new{ +local ReaderFooter = WidgetContainer:extend{ mode = MODE.page_progress, pageno = nil, pages = nil, @@ -510,6 +510,7 @@ end ReaderFooter.onUpdatePos = ReaderFooter.updateFooter function ReaderFooter:onReaderReady() + self.ui.menu:registerToMainMenu(self) self:setupTouchZones() self:resetLayout() -- set widget dimen self:setTocMarkers() diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index f2627c292..65db0b09a 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -1,3 +1,7 @@ +--[[-- +ReaderView module handles all the screen painting for document browsing. +]] + local AlphaContainer = require("ui/widget/container/alphacontainer") local ReaderFlipping = require("apps/reader/modules/readerflipping") local ReaderFooter = require("apps/reader/modules/readerfooter") @@ -13,7 +17,7 @@ local dbg = require("dbg") local Blitbuffer = require("ffi/blitbuffer") local _ = require("gettext") -local ReaderView = OverlapGroup:new{ +local ReaderView = OverlapGroup:extend{ document = nil, -- single page state @@ -75,14 +79,12 @@ local ReaderView = OverlapGroup:new{ } function ReaderView:init() + self.view_modules = {} -- fix recalculate from close document pageno self.state.page = nil -- fix inherited dim_area for following opened documents self:resetDimArea() self:addWidgets() - self.ui:registerPostInitCallback(function() - self.ui.menu:registerToMainMenu(self.footer) - end) self.emitHintPageEvent = function() self.ui:handleEvent(Event:new("HintPage", self.hinting)) end @@ -116,10 +118,37 @@ function ReaderView:addWidgets() self[3] = self.flipping end +--[[-- +Register a view UI widget module for document browsing. + +@tparam string name module name, registered widget can be accessed by readerui.view.view_modules[name]. +@tparam ui.widget.widget.Widget widget paintable widget, i.e. has a paintTo method. + +@usage +local ImageWidget = require("ui/widget/imagewidget") +local dummy_image = ImageWidget:new{ + file = "resources/icons/appbar.control.expand.png", +} +-- the image will be painted on all book pages +readerui.view:registerViewModule('dummy_image', dummy_image) +]] +function ReaderView:registerViewModule(name, widget) + if not widget.paintTo then + print(name .. " view module does not have paintTo method!") + return + end + widget.view = self + widget.ui = self.ui + self.view_modules[name] = widget +end + function ReaderView:resetLayout() - for i, widget in ipairs(self) do + for _, widget in ipairs(self) do widget:resetLayout() end + for _, m in pairs(self.view_modules) do + if m.resetLayout then m:resetLayout() end + end end function ReaderView:paintTo(bb, x, y) @@ -177,6 +206,9 @@ function ReaderView:paintTo(bb, x, y) if self.flipping_visible then self.flipping:paintTo(bb, x, y) end + for _, m in pairs(self.view_modules) do + m:paintTo(bb, x, y) + end -- stop activity indicator self.ui:handleEvent(Event:new("StopActivityIndicator")) end diff --git a/frontend/optmath.lua b/frontend/optmath.lua index 4ef0a6e17..8584fd960 100644 --- a/frontend/optmath.lua +++ b/frontend/optmath.lua @@ -1,6 +1,6 @@ --[[-- Simple math helper functions -]]-- +]] local Math = {} @@ -49,9 +49,10 @@ end Returns the minimum element of a table. The optional argument func specifies a one-argument ordering function. -@tparam tab -@tparam func -]]-- +@tparam table tab +@tparam func func +@treturn dynamic minimum element of a table +]] function Math.tmin(tab, func) return tmin_max(tab, func, "min") end @@ -60,9 +61,10 @@ end Returns the maximum element of a table. The optional argument func specifies a one-argument ordering function. -@tparam tab -@tparam func -]]-- +@tparam table tab +@tparam func func +@treturn dynamic maximum element of a table +]] function Math.tmax(tab, func) return tmin_max(tab, func, "max") end diff --git a/frontend/ui/widget/widget.lua b/frontend/ui/widget/widget.lua index e0308a361..dde29d80d 100644 --- a/frontend/ui/widget/widget.lua +++ b/frontend/ui/widget/widget.lua @@ -11,6 +11,9 @@ rather than class variables. ]] local EventListener = require("ui/widget/eventlistener") + +--- Widget base class +-- @table Widget local Widget = EventListener:new() --[[-- @@ -61,7 +64,7 @@ end --[[-- Paint widget to a BlitBuffer. -@tparam BlitBuffer BlitBuffer to paint to. If it's the screen BlitBuffer, then +@tparam BlitBuffer bb BlitBuffer to paint to. If it's the screen BlitBuffer, then widget will show up on screen refresh. @int x x offset within the BlitBuffer @int y y offset within the BlitBuffer diff --git a/plugins/statistics.koplugin/main.lua b/plugins/statistics.koplugin/main.lua index 2666a17ae..839ca030d 100755 --- a/plugins/statistics.koplugin/main.lua +++ b/plugins/statistics.koplugin/main.lua @@ -1,4 +1,4 @@ -local InputContainer = require("ui/widget/container/inputcontainer") +local Widget = require("ui/widget/widget") local MultiInputDialog = require("ui/widget/multiinputdialog") local KeyValuePage = require("ui/widget/keyvaluepage") local UIManager = require("ui/uimanager") @@ -20,7 +20,7 @@ local statistics_dir = DataStorage:getDataDir() .. "/statistics/" -- a copy of page_max_read_sec local page_max_time -local ReaderStatistics = InputContainer:new { +local ReaderStatistics = Widget:extend{ is_doc_only = true, last_time = nil, page_min_read_sec = 5,