From c0605955801694dc57fd009c63ba7e05bd15f476 Mon Sep 17 00:00:00 2001 From: poire-z Date: Thu, 14 Mar 2019 22:23:17 +0100 Subject: [PATCH] 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. --- .../apps/reader/modules/readerrolling.lua | 9 ++++++ frontend/ui/data/koptoptions.lua | 1 + frontend/ui/widget/configdialog.lua | 28 +++++++++++++++---- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/frontend/apps/reader/modules/readerrolling.lua b/frontend/apps/reader/modules/readerrolling.lua index d9259590f..2d354b877 100644 --- a/frontend/apps/reader/modules/readerrolling.lua +++ b/frontend/apps/reader/modules/readerrolling.lua @@ -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 diff --git a/frontend/ui/data/koptoptions.lua b/frontend/ui/data/koptoptions.lua index 019d071e6..654ba2d24 100644 --- a/frontend/ui/data/koptoptions.lua +++ b/frontend/ui/data/koptoptions.lua @@ -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 = { diff --git a/frontend/ui/widget/configdialog.lua b/frontend/ui/widget/configdialog.lua index 569dd2ece..ceeb086f2 100644 --- a/frontend/ui/widget/configdialog.lua +++ b/frontend/ui/widget/configdialog.lua @@ -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