mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
clean up refreshes
This is a larger clean-up of the refresh situation. The general shift is that refreshes are now mainly triggered by the (top-level) widgets when they get shown or closed via UIManager. All refreshes for the widgets when they are in use were handled by themselves before. This adds the case of showing/closing. It is the desired result of not having UIManager:show()/:close() do (full screen) refreshes on its own.
This commit is contained in:
@@ -62,7 +62,18 @@ function OPDSCatalog:init()
|
||||
background = Blitbuffer.COLOR_WHITE,
|
||||
opds_browser,
|
||||
}
|
||||
end
|
||||
|
||||
function OPDSCatalog:onShow()
|
||||
UIManager:setDirty(self, function()
|
||||
return "partial", self[1].dimen
|
||||
end)
|
||||
end
|
||||
|
||||
function OPDSCatalog:onCloseWidget()
|
||||
UIManager:setDirty(nil, function()
|
||||
return "partial", self[1].dimen
|
||||
end)
|
||||
end
|
||||
|
||||
function OPDSCatalog:showCatalog()
|
||||
|
||||
@@ -64,6 +64,20 @@ function PageCropDialog:init()
|
||||
}
|
||||
end
|
||||
|
||||
function PageCropDialog:onCloseWidget()
|
||||
UIManager:setDirty(nil, function()
|
||||
return "partial", self[1].dimen:combine(self[2].dimen)
|
||||
end)
|
||||
return true
|
||||
end
|
||||
|
||||
function PageCropDialog:onShow()
|
||||
UIManager:setDirty(self, function()
|
||||
return "partial", self[1].dimen:combine(self[2].dimen)
|
||||
end)
|
||||
return true
|
||||
end
|
||||
|
||||
local ReaderCropping = InputContainer:new{}
|
||||
|
||||
function ReaderCropping:onPageCrop(mode)
|
||||
|
||||
@@ -106,7 +106,7 @@ function ReaderDictionary:showDict(word, results, box)
|
||||
-- differentiate between dict and wiki
|
||||
wiki = self.wiki,
|
||||
}
|
||||
UIManager:show(self.dict_window, nil, nil, "none")
|
||||
UIManager:show(self.dict_window)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ function ReaderFont:onSetFontSize(new_size)
|
||||
UIManager:show(Notification:new{
|
||||
text = T( _("Font size set to %1."), self.font_size),
|
||||
timeout = 1,
|
||||
}, nil, nil, "none")
|
||||
})
|
||||
self.ui.document:setFontSize(Screen:scaleBySize(new_size))
|
||||
self.ui:handleEvent(Event:new("UpdatePos"))
|
||||
|
||||
|
||||
@@ -241,6 +241,7 @@ function ReaderHighlight:onHold(arg, ges)
|
||||
end
|
||||
UIManager:setDirty(self.dialog, "partial")
|
||||
-- TODO: only mark word?
|
||||
-- Unfortunately, CREngine does not return good coordinates
|
||||
-- UIManager:setDirty(self.dialog, "partial", self.selected_word.sbox)
|
||||
end
|
||||
return true
|
||||
@@ -368,9 +369,7 @@ function ReaderHighlight:onHoldRelease()
|
||||
},
|
||||
tap_close_callback = function() self:handleEvent(Event:new("Tap")) end,
|
||||
}
|
||||
UIManager:show(self.highlight_dialog, nil, nil, function()
|
||||
return "partial", self.highlight_dialog.dimen
|
||||
end)
|
||||
UIManager:show(self.highlight_dialog)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -394,7 +394,7 @@ function ReaderUI:onClose()
|
||||
DEBUG("closing document")
|
||||
self:onCloseDocument()
|
||||
end
|
||||
UIManager:close(self.dialog)
|
||||
UIManager:close(self.dialog, "full")
|
||||
-- serialize last used items for later launch
|
||||
Cache:serialize()
|
||||
running_instance = nil
|
||||
|
||||
@@ -128,8 +128,11 @@ function Screensaver:show()
|
||||
-- fallback to suspended message
|
||||
if not self.suspend_msg then
|
||||
self.suspend_msg = InfoMessage:new{ text = _("Suspended") }
|
||||
UIManager:show(self.suspend_msg)
|
||||
else
|
||||
-- refresh whole screen for other types
|
||||
UIManager:show(self.suspend_msg, "full")
|
||||
end
|
||||
UIManager:show(self.suspend_msg)
|
||||
end
|
||||
|
||||
function Screensaver:close()
|
||||
|
||||
@@ -15,6 +15,7 @@ local BBoxWidget = InputContainer:new{
|
||||
screen_bbox = nil,
|
||||
linesize = 2,
|
||||
fine_factor = 10,
|
||||
dimen = Geom:new(),
|
||||
}
|
||||
|
||||
function BBoxWidget:init()
|
||||
@@ -55,6 +56,9 @@ function BBoxWidget:getSize()
|
||||
end
|
||||
|
||||
function BBoxWidget:paintTo(bb, x, y)
|
||||
self.dimen = self.view.dimen:copy()
|
||||
self.dimen.x, self.dimen.y = x, y
|
||||
|
||||
-- As getScreenBBox uses view states, screen_bbox initialization is postponed.
|
||||
self.screen_bbox = self.screen_bbox or self:getScreenBBox(self.page_bbox)
|
||||
local bbox = self.screen_bbox
|
||||
|
||||
@@ -50,6 +50,18 @@ function ButtonDialog:init()
|
||||
}
|
||||
end
|
||||
|
||||
function ButtonDialog:onShow()
|
||||
UIManager:setDirty(self, function()
|
||||
return "partial", self[1][1].dimen
|
||||
end)
|
||||
end
|
||||
|
||||
function ButtonDialog:onCloseWidget()
|
||||
UIManager:setDirty(nil, function()
|
||||
return "partial", self[1][1].dimen
|
||||
end)
|
||||
end
|
||||
|
||||
function ButtonDialog:onTapClose()
|
||||
UIManager:close(self)
|
||||
if self.tap_close_callback then
|
||||
|
||||
@@ -520,6 +520,12 @@ function ConfigDialog:update()
|
||||
}
|
||||
end
|
||||
|
||||
function ConfigDialog:onCloseWidget()
|
||||
UIManager:setDirty("all", function()
|
||||
return "partial", self.dialog_frame.dimen
|
||||
end)
|
||||
end
|
||||
|
||||
function ConfigDialog:onShowConfigPanel(index)
|
||||
self.panel_index = index
|
||||
local old_dimen = self.dialog_frame.dimen and self.dialog_frame.dimen:copy()
|
||||
|
||||
@@ -87,7 +87,18 @@ function ConfirmBox:init()
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
function ConfirmBox:onShow()
|
||||
UIManager:setDirty(self, function()
|
||||
return "partial", self[1][1].dimen
|
||||
end)
|
||||
end
|
||||
|
||||
function ConfirmBox:onCloseWidget()
|
||||
UIManager:setDirty(nil, function()
|
||||
return "partial", self[1][1].dimen
|
||||
end)
|
||||
end
|
||||
|
||||
function ConfirmBox:onClose()
|
||||
|
||||
@@ -265,6 +265,20 @@ function DictQuickLookup:update()
|
||||
end)
|
||||
end
|
||||
|
||||
function DictQuickLookup:onCloseWidget()
|
||||
UIManager:setDirty(nil, function()
|
||||
return "partial", self.dict_frame.dimen
|
||||
end)
|
||||
return true
|
||||
end
|
||||
|
||||
function DictQuickLookup:onShow()
|
||||
UIManager:setDirty(self, function()
|
||||
return "partial", self.dict_frame.dimen
|
||||
end)
|
||||
return true
|
||||
end
|
||||
|
||||
function DictQuickLookup:isPrevDictAvaiable()
|
||||
return self.dict_index > 1
|
||||
end
|
||||
|
||||
@@ -25,7 +25,6 @@ local InfoMessage = InputContainer:new{
|
||||
face = Font:getFace("infofont", 25),
|
||||
text = "",
|
||||
timeout = nil, -- in seconds
|
||||
closed = false,
|
||||
}
|
||||
|
||||
function InfoMessage:init()
|
||||
@@ -79,30 +78,32 @@ function InfoMessage:init()
|
||||
}
|
||||
end
|
||||
|
||||
function InfoMessage:close()
|
||||
if not self.closed then
|
||||
self.closed = true
|
||||
UIManager:close(self, "partial", self[1][1].dimen)
|
||||
end
|
||||
function InfoMessage:onCloseWidget()
|
||||
UIManager:setDirty(nil, function()
|
||||
return "partial", self[1][1].dimen
|
||||
end)
|
||||
return true
|
||||
end
|
||||
|
||||
function InfoMessage:onShow()
|
||||
-- triggered by the UIManager after we got successfully shown (not yet painted)
|
||||
UIManager:setDirty(self, function()
|
||||
return "partial", self[1][1].dimen
|
||||
end)
|
||||
if self.timeout then
|
||||
UIManager:scheduleIn(self.timeout, function() self:close() end)
|
||||
UIManager:scheduleIn(self.timeout, function() UIManager:close(self) end)
|
||||
end
|
||||
self.closed = false
|
||||
return true
|
||||
end
|
||||
|
||||
function InfoMessage:onAnyKeyPressed()
|
||||
-- triggered by our defined key events
|
||||
self:close()
|
||||
UIManager:close(self)
|
||||
return true
|
||||
end
|
||||
|
||||
function InfoMessage:onTapClose()
|
||||
self:close()
|
||||
UIManager:close(self)
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
@@ -116,8 +116,18 @@ function InputDialog:init()
|
||||
},
|
||||
self.dialog_frame,
|
||||
}
|
||||
-- do a full refresh - is this really needed?
|
||||
UIManager:setDirty("all", "full")
|
||||
end
|
||||
|
||||
function InputDialog:onShow()
|
||||
UIManager:setDirty(self, function()
|
||||
return "partial", self.dialog_frame.dimen
|
||||
end)
|
||||
end
|
||||
|
||||
function InputDialog:onCloseWidget()
|
||||
UIManager:setDirty(nil, function()
|
||||
return "partial", self.dialog_frame.dimen
|
||||
end)
|
||||
end
|
||||
|
||||
function InputDialog:onShowKeyboard()
|
||||
|
||||
@@ -87,6 +87,10 @@ function InputText:initTextBox(text)
|
||||
text_widget,
|
||||
}
|
||||
self.dimen = self[1]:getSize()
|
||||
|
||||
UIManager:setDirty(self.parent, function()
|
||||
return "partial", self[1].dimen
|
||||
end)
|
||||
end
|
||||
|
||||
function InputText:initCharlist(text)
|
||||
@@ -154,9 +158,6 @@ function InputText:addChar(char)
|
||||
table.insert(self.charlist, self.charpos, char)
|
||||
self.charpos = self.charpos + 1
|
||||
self:initTextBox(table.concat(self.charlist))
|
||||
UIManager:setDirty(self.parent, function()
|
||||
return "ui", self.dimen
|
||||
end)
|
||||
end
|
||||
|
||||
function InputText:delChar()
|
||||
@@ -164,13 +165,12 @@ function InputText:delChar()
|
||||
self.charpos = self.charpos - 1
|
||||
table.remove(self.charlist, self.charpos)
|
||||
self:initTextBox(table.concat(self.charlist))
|
||||
UIManager:setDirty(self.parent, "ui")
|
||||
end
|
||||
|
||||
function InputText:clear()
|
||||
self:initTextBox("")
|
||||
UIManager:setDirty(self.parent, function()
|
||||
return "ui", self.dimen
|
||||
return "ui", self[1][1].dimen
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -181,7 +181,7 @@ end
|
||||
function InputText:setText(text)
|
||||
self:initTextBox(text)
|
||||
UIManager:setDirty(self.parent, function()
|
||||
return "partial", self.dimen
|
||||
return "partial", self[1].dimen
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
@@ -33,7 +33,17 @@ function LinkBox:paintTo(bb)
|
||||
self.bordersize, self.color, self.radius)
|
||||
end
|
||||
|
||||
function LinkBox:onCloseWidget()
|
||||
UIManager:setDirty(nil, function()
|
||||
return "partial", self.box
|
||||
end)
|
||||
return true
|
||||
end
|
||||
|
||||
function LinkBox:onShow()
|
||||
UIManager:setDirty(self, function()
|
||||
return "partial", self.box
|
||||
end)
|
||||
if self.timeout then
|
||||
UIManager:scheduleIn(self.timeout, function()
|
||||
UIManager:close(self)
|
||||
|
||||
@@ -87,7 +87,6 @@ function LoginDialog:init()
|
||||
},
|
||||
self.dialog_frame,
|
||||
}
|
||||
UIManager:setDirty("all", "full")
|
||||
end
|
||||
|
||||
function LoginDialog:getCredential()
|
||||
|
||||
@@ -283,11 +283,13 @@ end
|
||||
function MenuItem:onTapSelect(arg, ges)
|
||||
local pos = self:getGesPosition(ges)
|
||||
self[1].invert = true
|
||||
-- TODO: regional refresh
|
||||
UIManager:setDirty(self.show_parent, "partial")
|
||||
local refreshfunc = function()
|
||||
return "partial", self[1].dimen
|
||||
end
|
||||
UIManager:setDirty(self.show_parent, refreshfunc)
|
||||
UIManager:scheduleIn(0.1, function()
|
||||
self[1].invert = false
|
||||
UIManager:setDirty(self.show_parent, "partial")
|
||||
UIManager:setDirty(self.show_parent, refreshfunc)
|
||||
self.menu:onMenuSelect(self.table, pos)
|
||||
end)
|
||||
return true
|
||||
@@ -296,11 +298,13 @@ end
|
||||
function MenuItem:onHoldSelect(arg, ges)
|
||||
local pos = self:getGesPosition(ges)
|
||||
self[1].invert = true
|
||||
-- TODO: regional refresh
|
||||
UIManager:setDirty(self.show_parent, "partial")
|
||||
local refreshfunc = function()
|
||||
return "partial", self[1].dimen
|
||||
end
|
||||
UIManager:setDirty(self.show_parent, refreshfunc)
|
||||
UIManager:scheduleIn(0.1, function()
|
||||
self[1].invert = false
|
||||
UIManager:setDirty(self.show_parent, "partial")
|
||||
UIManager:setDirty(self.show_parent, refreshfunc)
|
||||
self.menu:onMenuHold(self.table, pos)
|
||||
end)
|
||||
return true
|
||||
|
||||
@@ -20,7 +20,6 @@ local Notification = InputContainer:new{
|
||||
timeout = nil,
|
||||
margin = 5,
|
||||
padding = 5,
|
||||
closed = false,
|
||||
}
|
||||
|
||||
function Notification:init()
|
||||
@@ -56,25 +55,27 @@ function Notification:init()
|
||||
}
|
||||
end
|
||||
|
||||
function Notification:close()
|
||||
if not self.closed then
|
||||
self.closed = true
|
||||
UIManager:close(self, "partial", self[1][1].dimen)
|
||||
end
|
||||
function Notification:onCloseWidget()
|
||||
UIManager:setDirty(nil, function()
|
||||
return "partial", self[1][1].dimen
|
||||
end)
|
||||
return true
|
||||
end
|
||||
|
||||
function Notification:onShow()
|
||||
-- triggered by the UIManager after we got successfully shown (not yet painted)
|
||||
UIManager:setDirty(self, function()
|
||||
return "partial", self[1][1].dimen
|
||||
end)
|
||||
if self.timeout then
|
||||
UIManager:scheduleIn(self.timeout, function() self:close() end)
|
||||
UIManager:scheduleIn(self.timeout, function() UIManager:close(self) end)
|
||||
end
|
||||
self.closed = false
|
||||
return true
|
||||
end
|
||||
|
||||
function Notification:onAnyKeyPressed()
|
||||
-- triggered by our defined key events
|
||||
self:close()
|
||||
UIManager:close(self)
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
@@ -102,21 +102,9 @@ function VirtualKey:update_keyboard()
|
||||
end)
|
||||
end
|
||||
|
||||
function VirtualKey:update_keyboard_inputbox()
|
||||
local inputbox = self.keyboard.inputbox
|
||||
UIManager:setDirty(self.keyboard, function()
|
||||
DEBUG("update inputbox", inputbox.dimen)
|
||||
return "ui", inputbox.dimen
|
||||
end)
|
||||
UIManager:setDirty(self.keyboard, function()
|
||||
DEBUG("update keyboard", self[1].dimen)
|
||||
return "ui", self[1].dimen
|
||||
end)
|
||||
end
|
||||
|
||||
function VirtualKey:onTapSelect()
|
||||
self[1].invert = true
|
||||
self:update_keyboard_inputbox()
|
||||
self:update_keyboard()
|
||||
if self.callback then
|
||||
self.callback()
|
||||
end
|
||||
@@ -126,7 +114,7 @@ end
|
||||
|
||||
function VirtualKey:onHoldSelect()
|
||||
self[1].invert = true
|
||||
self:update_keyboard_inputbox()
|
||||
self:update_keyboard()
|
||||
if self.hold_callback then
|
||||
self.hold_callback()
|
||||
end
|
||||
@@ -227,6 +215,22 @@ function VirtualKeyboard:init()
|
||||
self:initLayout(self.layout)
|
||||
end
|
||||
|
||||
function VirtualKeyboard:_refresh()
|
||||
UIManager:setDirty(self, function()
|
||||
return "partial", self[1][1].dimen
|
||||
end)
|
||||
end
|
||||
|
||||
function VirtualKeyboard:onShow()
|
||||
self:_refresh()
|
||||
return true
|
||||
end
|
||||
|
||||
function VirtualKeyboard:onCloseWidget()
|
||||
self:_refresh()
|
||||
return true
|
||||
end
|
||||
|
||||
function VirtualKeyboard:initLayout(layout)
|
||||
local function VKLayout(b1, b2, b3, b4)
|
||||
local function boolnum(bool)
|
||||
@@ -319,13 +323,7 @@ function VirtualKeyboard:setLayout(key)
|
||||
if self.utf8mode then self.umlautmode = false end
|
||||
end
|
||||
self:initLayout()
|
||||
UIManager:setDirty(self, function()
|
||||
-- correct coordinates of keyboard
|
||||
local dimen = self.dimen:copy()
|
||||
dimen.y = Screen:getHeight() - dimen.h
|
||||
DEBUG("update keyboard layout", dimen)
|
||||
return "partial", dimen
|
||||
end)
|
||||
self:_refresh()
|
||||
end
|
||||
|
||||
function VirtualKeyboard:addChar(key)
|
||||
|
||||
Reference in New Issue
Block a user