mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
ConfigDialog: fix ButtonProgressWidget and some refreshes (#4793)
This internal ButtonProgressWidget widget was behaving differently from all others (OptionTextItem, OptionIconItem and ToggleSwitch) by duplicating some code from ConfigDialog:onConfigChoose() instead of calling it directly. While making it similar to others, I noticed that onConfigChoose() did a full repaint, which was necessary for some settings to be applied (ie: Contrast). On CreDocument, this full repaint may cause some double drawing on config changes (ie: Margins, drawing once after margin changes, and then re-positionning to previous xpointer). So, make the need for full repaint a condition on KoptOptions.
This commit is contained in:
@@ -643,6 +643,15 @@ function ReaderRolling:onUpdatePos()
|
||||
-- we have set above) to avoid multiple refreshes.
|
||||
return true
|
||||
end
|
||||
-- Calling this now ensures the re-rendering is done by crengine
|
||||
-- so the delayed updatePos() has good info and can reposition
|
||||
-- the previous xpointer accurately:
|
||||
self.ui.document:getCurrentPos()
|
||||
-- Otherwise, _readMetadata() would do that, but the positionning
|
||||
-- would not work as expected, for some reason (it worked
|
||||
-- previously because of some bad setDirty() in ConfigDialog widgets
|
||||
-- that were triggering a full repaint of crengine (so, the needed
|
||||
-- rerendering) before updatePos() is called.
|
||||
UIManager:scheduleIn(0.1, function () self:updatePos() end)
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -6,6 +6,7 @@ local Screen = Device.screen
|
||||
|
||||
local KoptOptions = {
|
||||
prefix = 'kopt',
|
||||
needs_redraw_on_change = true,
|
||||
{
|
||||
icon = "resources/icons/appbar.transform.rotate.right.large.png",
|
||||
options = {
|
||||
|
||||
@@ -499,7 +499,8 @@ function ConfigOption:init()
|
||||
local max_buttonprogress_width = option_widget_width
|
||||
local buttonprogress_width = self.options[c].width and Screen:scaleBySize(self.options[c].width)
|
||||
or max_buttonprogress_width
|
||||
local switch = ButtonProgressWidget:new{
|
||||
local switch
|
||||
switch = ButtonProgressWidget:new{
|
||||
width = math.min(max_buttonprogress_width, buttonprogress_width),
|
||||
height = option_height,
|
||||
padding = 0,
|
||||
@@ -509,10 +510,10 @@ function ConfigOption:init()
|
||||
num_buttons = #self.options[c].values,
|
||||
position = self.options[c].default_pos,
|
||||
callback = function(arg)
|
||||
UIManager:tickAfterNext(function()
|
||||
self.config:onConfigChoice(self.options[c].name, self.options[c].values[arg])
|
||||
self.config:onConfigEvent(self.options[c].event, self.options[c].args[arg])
|
||||
UIManager:setDirty("all")
|
||||
self.config:onConfigChoose(self.options[c].values, self.options[c].name,
|
||||
self.options[c].event, self.options[c].args, self.options[c].events, arg)
|
||||
UIManager:setDirty(self.config, function()
|
||||
return "fast", switch.dimen
|
||||
end)
|
||||
end,
|
||||
hold_callback = function(arg)
|
||||
@@ -840,8 +841,23 @@ function ConfigDialog:onConfigChoose(values, name, event, args, events, position
|
||||
if events then
|
||||
self:onConfigEvents(events, position)
|
||||
end
|
||||
-- Even if each toggle refreshes itself when toggled, we still
|
||||
-- need to update and repaint the whole config panel, as other
|
||||
-- toggles may have their state (enabled/disabled) modified
|
||||
-- after this toggle update.
|
||||
self:update()
|
||||
UIManager:setDirty("all")
|
||||
if self.config_options.needs_redraw_on_change then
|
||||
-- Some Kopt document event handlers just save their setting,
|
||||
-- and need a full repaint for kopt to load these settings,
|
||||
-- notice the change, and redraw the document
|
||||
UIManager:setDirty("all", "partial")
|
||||
else
|
||||
-- CreDocument event handlers do their own refresh:
|
||||
-- we can just redraw our frame
|
||||
UIManager:setDirty(self, function()
|
||||
return "ui", self.dialog_frame.dimen
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user