From b92c078e9c68325c5a1ae41a9d71620fd7b854af Mon Sep 17 00:00:00 2001 From: poire-z Date: Mon, 11 Jan 2021 18:14:17 +0100 Subject: [PATCH] ConfigDialog: temporarily hide when showing SpinWidgets Hide bottom panel when showing a SpinWidget, so we gain on the bottom the space covered by the SpinWidget to see more how a change is affecting the book text. For clarity, rename delay_repaint & refresh_callback to hide_on_apply & when_applied_callback. Normalize SpinWidgets: have them both accept a cancel_callback and a close_callback. InfoMessage: call dissmiss_callback also on timeout. --- .../apps/reader/modules/readertypeset.lua | 36 ++-- frontend/ui/data/creoptions.lua | 8 +- frontend/ui/widget/configdialog.lua | 191 ++++++++++-------- frontend/ui/widget/doublespinwidget.lua | 11 +- frontend/ui/widget/infomessage.lua | 17 +- frontend/ui/widget/spinwidget.lua | 13 +- frontend/ui/widget/toggleswitch.lua | 2 +- 7 files changed, 162 insertions(+), 116 deletions(-) diff --git a/frontend/apps/reader/modules/readertypeset.lua b/frontend/apps/reader/modules/readertypeset.lua index 4ffc21fef..2c067405a 100644 --- a/frontend/apps/reader/modules/readertypeset.lua +++ b/frontend/apps/reader/modules/readertypeset.lua @@ -430,32 +430,32 @@ function ReaderTypeset:makeDefaultStyleSheet(css, text, touchmenu_instance) }) end -function ReaderTypeset:onSetPageHorizMargins(h_margins, refresh_callback) +function ReaderTypeset:onSetPageHorizMargins(h_margins, when_applied_callback) self.unscaled_margins = { h_margins[1], self.unscaled_margins[2], h_margins[2], self.unscaled_margins[4] } - self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins, refresh_callback)) + self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins, when_applied_callback)) end -function ReaderTypeset:onSetPageTopMargin(t_margin, refresh_callback) +function ReaderTypeset:onSetPageTopMargin(t_margin, when_applied_callback) self.unscaled_margins = { self.unscaled_margins[1], t_margin, self.unscaled_margins[3], self.unscaled_margins[4] } if self.sync_t_b_page_margins then self.unscaled_margins[4] = t_margin -- Let ConfigDialog know so it can update it on screen and have it saved on quit self.ui.document.configurable.b_page_margin = t_margin end - self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins, refresh_callback)) + self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins, when_applied_callback)) end -function ReaderTypeset:onSetPageBottomMargin(b_margin, refresh_callback) +function ReaderTypeset:onSetPageBottomMargin(b_margin, when_applied_callback) self.unscaled_margins = { self.unscaled_margins[1], self.unscaled_margins[2], self.unscaled_margins[3], b_margin } if self.sync_t_b_page_margins then self.unscaled_margins[2] = b_margin -- Let ConfigDialog know so it can update it on screen and have it saved on quit self.ui.document.configurable.t_page_margin = b_margin end - self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins, refresh_callback)) + self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins, when_applied_callback)) end -function ReaderTypeset:onSetPageTopAndBottomMargin(t_b_margins, refresh_callback) +function ReaderTypeset:onSetPageTopAndBottomMargin(t_b_margins, when_applied_callback) local t_margin, b_margin = t_b_margins[1], t_b_margins[2] self.unscaled_margins = { self.unscaled_margins[1], t_margin, self.unscaled_margins[3], b_margin } if t_margin ~= b_margin then @@ -463,10 +463,10 @@ function ReaderTypeset:onSetPageTopAndBottomMargin(t_b_margins, refresh_callback self.sync_t_b_page_margins = false self.ui.document.configurable.sync_t_b_page_margins = 0 end - self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins, refresh_callback)) + self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins, when_applied_callback)) end -function ReaderTypeset:onSyncPageTopBottomMargins(toggle, refresh_callback) +function ReaderTypeset:onSyncPageTopBottomMargins(toggle, when_applied_callback) self.sync_t_b_page_margins = not self.sync_t_b_page_margins if self.sync_t_b_page_margins then -- Adjust current top and bottom margins if needed @@ -481,16 +481,16 @@ function ReaderTypeset:onSyncPageTopBottomMargins(toggle, refresh_callback) self.ui.document.configurable.t_page_margin = mean_margin self.ui.document.configurable.b_page_margin = mean_margin self.unscaled_margins = { self.unscaled_margins[1], mean_margin, self.unscaled_margins[3], mean_margin } - self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins, refresh_callback)) - refresh_callback = nil + self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins, when_applied_callback)) + when_applied_callback = nil end end - if refresh_callback then - refresh_callback() + if when_applied_callback then + when_applied_callback() end end -function ReaderTypeset:onSetPageMargins(margins, refresh_callback) +function ReaderTypeset:onSetPageMargins(margins, when_applied_callback) local left = Screen:scaleBySize(margins[1]) local top = Screen:scaleBySize(margins[2]) local right = Screen:scaleBySize(margins[3]) @@ -502,8 +502,10 @@ function ReaderTypeset:onSetPageMargins(margins, refresh_callback) end self.ui.document:setPageMargins(left, top, right, bottom) self.ui:handleEvent(Event:new("UpdatePos")) - if refresh_callback then - -- Show a toast on set, with the unscaled & scaled values + if when_applied_callback then + -- Provided when hide_on_apply, and ConfigDialog temporarily hidden: + -- show an InfoMessage with the unscaled & scaled values, + -- and call when_applied_callback on dismiss UIManager:show(InfoMessage:new{ text = T(_([[ Margins set to: @@ -515,7 +517,7 @@ Margins set to: Tap to dismiss.]]), margins[1], left, margins[3], right, margins[2], top, margins[4], bottom), - dismiss_callback = refresh_callback, + dismiss_callback = when_applied_callback, }) end end diff --git a/frontend/ui/data/creoptions.lua b/frontend/ui/data/creoptions.lua index e640a4c2b..dbe71a110 100644 --- a/frontend/ui/data/creoptions.lua +++ b/frontend/ui/data/creoptions.lua @@ -90,7 +90,7 @@ Note that this may not be ensured under some conditions: in scroll mode, when a DCREREADER_CONFIG_H_MARGIN_SIZES_X_HUGE, DCREREADER_CONFIG_H_MARGIN_SIZES_XX_HUGE, }, - delay_repaint = true, + hide_on_apply = true, name_text_hold_callback = optionsutil.showValuesHMargins, more_options = true, more_options_param = { @@ -114,7 +114,7 @@ Note that this may not be ensured under some conditions: in scroll mode, when a event = "SyncPageTopBottomMargins", args = {false, true}, default_arg = false, - delay_repaint = true, + hide_on_apply = true, name_text_hold_callback = optionsutil.showValues, help_text = _([[Keep top and bottom margins synchronized. - 'off' allows different top and bottom margins. @@ -151,7 +151,7 @@ In the top menu → Settings → Status bar, you can choose whether the bottom m DCREREADER_CONFIG_T_MARGIN_SIZES_X_HUGE, DCREREADER_CONFIG_T_MARGIN_SIZES_XX_HUGE, }, - delay_repaint = true, + hide_on_apply = true, name_text_hold_callback = optionsutil.showValues, more_options = true, more_options_param = { @@ -202,7 +202,7 @@ In the top menu → Settings → Status bar, you can choose whether the bottom m DCREREADER_CONFIG_B_MARGIN_SIZES_X_HUGE, DCREREADER_CONFIG_B_MARGIN_SIZES_XX_HUGE, }, - delay_repaint = true, + hide_on_apply = true, name_text_hold_callback = optionsutil.showValues, help_text = _([[In the top menu → Settings → Status bar, you can choose whether the bottom margin applies from the bottom of the screen, or from above the status bar.]]), more_options = true, diff --git a/frontend/ui/widget/configdialog.lua b/frontend/ui/widget/configdialog.lua index e4ee9d197..de7109fdc 100644 --- a/frontend/ui/widget/configdialog.lua +++ b/frontend/ui/widget/configdialog.lua @@ -87,7 +87,7 @@ function OptionTextItem:onTapSelect() self.underline_container.color = Blitbuffer.COLOR_BLACK self.config:onConfigChoose(self.values, self.name, self.event, self.args, - self.events, self.current_item) + self.events, self.current_item, self.hide_on_apply) UIManager:setDirty(self.config, function() return "fast", self[1].dimen end) @@ -159,7 +159,7 @@ function OptionIconItem:onTapSelect() self.underline_container.color = Blitbuffer.COLOR_BLACK self.config:onConfigChoose(self.values, self.name, self.event, self.args, - self.events, self.current_item) + self.events, self.current_item, self.hide_on_apply) UIManager:setDirty(self.config, function() return "fast", self[1].dimen end) @@ -478,6 +478,7 @@ function ConfigOption:init() option_item.args = self.options[c].args option_item.event = self.options[c].event option_item.current_item = d + option_item.hide_on_apply = self.options[c].hide_on_apply option_item.config = self.config option_item.document = self.document table.insert(option_items_group, option_item) @@ -518,6 +519,7 @@ function ConfigOption:init() option_item.args = self.options[c].args option_item.event = self.options[c].event option_item.current_item = d + option_item.hide_on_apply = self.options[c].hide_on_apply option_item.config = self.config table.insert(option_items_group, option_item) end @@ -549,7 +551,7 @@ function ConfigOption:init() args = self.options[c].args, event = self.options[c].event, events = self.options[c].events, - delay_repaint = self.options[c].delay_repaint, + hide_on_apply = self.options[c].hide_on_apply, config = self.config, enabled = enabled, row_count = row_count, @@ -559,7 +561,7 @@ function ConfigOption:init() self.options[c].more_options_param.show_true_value_func = self.options[c].show_true_value_func end self.config:onConfigMoreChoose(self.options[c].values, self.options[c].name, - self.options[c].event, arg, name_text, self.options[c].delay_repaint, self.options[c].more_options_param) + self.options[c].event, arg, name_text, self.options[c].more_options_param) end end } @@ -587,14 +589,14 @@ function ConfigOption:init() callback = function(arg) if arg == "-" or arg == "+" then self.config:onConfigFineTuneChoose(self.options[c].values, self.options[c].name, - self.options[c].event, self.options[c].args, self.options[c].events, arg, self.options[c].delay_repaint, + self.options[c].event, self.options[c].args, self.options[c].events, arg, self.options[c].hide_on_apply, self.options[c].fine_tune_param) elseif arg == "⋮" then self.config:onConfigMoreChoose(self.options[c].values, self.options[c].name, - self.options[c].event, arg, name_text, self.options[c].delay_repaint, self.options[c].more_options_param) + self.options[c].event, arg, name_text, self.options[c].more_options_param) else self.config:onConfigChoose(self.options[c].values, self.options[c].name, - self.options[c].event, self.options[c].args, self.options[c].events, arg, self.options[c].delay_repaint) + self.options[c].event, self.options[c].args, self.options[c].events, arg, self.options[c].hide_on_apply) end UIManager:setDirty(self.config, function() return "fast", switch.dimen @@ -923,8 +925,8 @@ function ConfigDialog:onConfigChoice(option_name, option_value) return true end -function ConfigDialog:onConfigEvent(option_event, option_arg, refresh_callback) - self.ui:handleEvent(Event:new(option_event, option_arg, refresh_callback)) +function ConfigDialog:onConfigEvent(option_event, option_arg, when_applied_callback) + self.ui:handleEvent(Event:new(option_event, option_arg, when_applied_callback)) return true end @@ -936,7 +938,7 @@ function ConfigDialog:onConfigEvents(option_events, arg_index) return true end -function ConfigDialog:onConfigChoose(values, name, event, args, events, position, delay_repaint) +function ConfigDialog:onConfigChoose(values, name, event, args, events, position, hide_on_apply) UIManager:tickAfterNext(function() -- Repainting may be delayed depending on options local refresh_dialog_func = function() @@ -954,15 +956,15 @@ function ConfigDialog:onConfigChoose(values, name, event, args, events, position end) end end - local refresh_callback = nil - if type(delay_repaint) == "number" then -- timeout - UIManager:scheduleIn(delay_repaint, refresh_dialog_func) + local when_applied_callback = nil + if type(hide_on_apply) == "number" then -- timeout + UIManager:scheduleIn(hide_on_apply, refresh_dialog_func) self.skip_paint = true - elseif delay_repaint then -- anything but nil or false: provide a callback + elseif hide_on_apply then -- anything but nil or false: provide a callback -- This needs the config option to have an "event" key -- The event handler is responsible for calling this callback when -- it considers it appropriate - refresh_callback = refresh_dialog_func + when_applied_callback = refresh_dialog_func self.skip_paint = true end if values then @@ -970,7 +972,7 @@ function ConfigDialog:onConfigChoose(values, name, event, args, events, position end if event then args = args or {} - self:onConfigEvent(event, args[position], refresh_callback) + self:onConfigEvent(event, args[position], when_applied_callback) end if events then self:onConfigEvents(events, position) @@ -980,14 +982,14 @@ function ConfigDialog:onConfigChoose(values, name, event, args, events, position -- toggles may have their state (enabled/disabled) modified -- after this toggle update. self:update() - if not delay_repaint then -- immediate refresh + if not hide_on_apply then -- immediate refresh refresh_dialog_func() end end) end -- Tweaked variant used with the fine_tune variant of buttonprogress (direction can only be "-" or "+") -function ConfigDialog:onConfigFineTuneChoose(values, name, event, args, events, direction, delay_repaint, params) +function ConfigDialog:onConfigFineTuneChoose(values, name, event, args, events, direction, hide_on_apply, params) UIManager:tickAfterNext(function() -- Repainting may be delayed depending on options local refresh_dialog_func = function() @@ -1005,15 +1007,15 @@ function ConfigDialog:onConfigFineTuneChoose(values, name, event, args, events, end) end end - local refresh_callback = nil - if type(delay_repaint) == "number" then -- timeout - UIManager:scheduleIn(delay_repaint, refresh_dialog_func) + local when_applied_callback = nil + if type(hide_on_apply) == "number" then -- timeout + UIManager:scheduleIn(hide_on_apply, refresh_dialog_func) self.skip_paint = true - elseif delay_repaint then -- anything but nil or false: provide a callback + elseif hide_on_apply then -- anything but nil or false: provide a callback -- This needs the config option to have an "event" key -- The event handler is responsible for calling this callback when -- it considers it appropriate - refresh_callback = refresh_dialog_func + when_applied_callback = refresh_dialog_func self.skip_paint = true end if values then @@ -1070,7 +1072,7 @@ function ConfigDialog:onConfigFineTuneChoose(values, name, event, args, events, arg = arg + 1 end end - self:onConfigEvent(event, arg, refresh_callback) + self:onConfigEvent(event, arg, when_applied_callback) end if events then self:onConfigEvents(events, direction) @@ -1080,7 +1082,7 @@ function ConfigDialog:onConfigFineTuneChoose(values, name, event, args, events, -- toggles may have their state (enabled/disabled) modified -- after this toggle update. self:update() - if not delay_repaint then -- immediate refresh + if not hide_on_apply then -- immediate refresh refresh_dialog_func() end end) @@ -1088,14 +1090,16 @@ end -- Tweaked variant used with the more options variant of buttonprogress and fine tune with numpicker -- events are not supported -function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, delay_repaint, more_options_param) +function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, more_options_param) if not more_options_param then more_options_param = {} end UIManager:tickAfterNext(function() -- Repainting may be delayed depending on options - local refresh_dialog_func = function() - self.skip_paint = nil + local refresh_dialog_func = function(keep_skip_paint) + if self.skip_paint and not keep_skip_paint then + self.skip_paint = nil + end 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, @@ -1104,20 +1108,31 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, d 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) + if self.skip_paint then + -- Redraw anything below the now hidden ConfigDialog + UIManager:setDirty("all", function() + return "partial", self.dialog_frame.dimen + end) + else + UIManager:setDirty(self, function() + return "ui", self.dialog_frame.dimen + end) + end end end - local refresh_callback = nil - if type(delay_repaint) == "number" then -- timeout - UIManager:scheduleIn(delay_repaint, refresh_dialog_func) + local hide_on_picker_show = more_options_param.hide_on_picker_show + if hide_on_picker_show == nil then -- default to true if unset + hide_on_picker_show = true + end + local when_applied_callback = nil + if type(hide_on_picker_show) == "number" then -- timeout + UIManager:scheduleIn(hide_on_picker_show, refresh_dialog_func) self.skip_paint = true - elseif delay_repaint then -- anything but nil or false: provide a callback + elseif hide_on_picker_show then -- anything but nil or false: provide a callback -- This needs the config option to have an "event" key -- The event handler is responsible for calling this callback when -- it considers it appropriate - refresh_callback = refresh_dialog_func + when_applied_callback = refresh_dialog_func self.skip_paint = true end if values and event then @@ -1142,6 +1157,8 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, d curr_values = self.configurable[name] end widget = DoubleSpinWidget:new{ + title_text = name_text or _("Set values"), + info_text = more_options_param.info_text, width = math.floor(Screen:getWidth() * 0.6), left_text = more_options_param.left_text, right_text = more_options_param.right_text, @@ -1155,16 +1172,14 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, d right_max = more_options_param.right_max, right_step = more_options_param.right_step, right_hold_step = more_options_param.right_hold_step, - title_text = name_text or _("Set values"), - info_text = more_options_param.info_text, keep_shown_on_apply = true, - callback = function(left_value, right_value) - if widget:hasMoved() and not self._dialog_closed then - -- If it has been moved, assume the user wants more - -- space and close bottom dialog - self._dialog_closed = true - self:closeDialog() + close_callback = function() + if when_applied_callback then + when_applied_callback() + when_applied_callback = nil end + end, + callback = function(left_value, right_value) local value_tables = { left_value, right_value } if more_options_param.names then self:onConfigChoice(more_options_param.names[1], left_value) @@ -1173,8 +1188,13 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, d self:onConfigChoice(name, value_tables) end if event then + -- Repainting (with when_applied_callback) if hide_on_picker_show + -- is done in close_callback, but we want onConfigEvent to + -- show a message when settings applied: handlers that can do + -- it actually do it when provided a callback as argument + local dummy_callback = when_applied_callback and function() end args = args or {} - self:onConfigEvent(event, value_tables, refresh_callback) + self:onConfigEvent(event, value_tables, dummy_callback) self:update() end end, @@ -1206,7 +1226,6 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, d end) end, }) - end, } else -- SpinWidget with single value @@ -1232,6 +1251,8 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, d end end widget = SpinWidget:new{ + title_text = name_text or _("Set value"), + info_text = more_options_param.info_text, width = math.floor(Screen:getWidth() * 0.6), value = curr_items, value_index = value_index, @@ -1242,6 +1263,41 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, d value_max = more_options_param.value_max or values[#values], precision = more_options_param.precision or "%02d", keep_shown_on_apply = true, + close_callback = function() + if when_applied_callback then + when_applied_callback() + when_applied_callback = nil + end + end, + callback = function(spin) + if more_options_param.value_table then + if more_options_param.args_table then + self:onConfigChoice(name, more_options_param.args_table[spin.value_index]) + else + self:onConfigChoice(name, spin.value_index) + end + else + self:onConfigChoice(name, spin.value) + end + if event then + -- Repainting (with when_applied_callback) if hide_on_picker_show + -- is done in close_callback, but we want onConfigEvent to + -- show a message when settings applied: handlers that can do + -- it actually do it when provided a callback as argument + local dummy_callback = when_applied_callback and function() end + args = args or {} + if more_options_param.value_table then + if more_options_param.args_table then + self:onConfigEvent(event, more_options_param.args_table[spin.value_index], dummy_callback) + else + self:onConfigEvent(event, spin.value_index, dummy_callback) + end + else + self:onConfigEvent(event, spin.value, dummy_callback) + end + self:update() + end + end, extra_text = _("Set as default"), extra_callback = function(spin) local value_string @@ -1270,51 +1326,14 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, d end) end, }) - end, - title_text = name_text or _("Set value"), - info_text = more_options_param.info_text, - callback = function(spin) - if widget:hasMoved() and not self._dialog_closed then - -- If it has been moved, assume the user wants more - -- space and close bottom dialog - self._dialog_closed = true - self:closeDialog() - end - if more_options_param.value_table then - if more_options_param.args_table then - self:onConfigChoice(name, more_options_param.args_table[spin.value_index]) - else - self:onConfigChoice(name, spin.value_index) - end - else - self:onConfigChoice(name, spin.value) - end - if event then - args = args or {} - if more_options_param.value_table then - if more_options_param.args_table then - self:onConfigEvent(event, more_options_param.args_table[spin.value_index], refresh_callback) - else - self:onConfigEvent(event, spin.value_index, refresh_callback) - end - else - self:onConfigEvent(event, spin.value, refresh_callback) - end - self:update() - end - end } end - if delay_repaint then - self._dialog_closed = true - self:closeDialog() - end UIManager:show(widget) end - if not delay_repaint then -- immediate refresh - refresh_dialog_func() - end + -- Even if skip_paint (to temporarily hide it), we need + -- to issue setDirty for what's below to be painted + refresh_dialog_func(true) end) end diff --git a/frontend/ui/widget/doublespinwidget.lua b/frontend/ui/widget/doublespinwidget.lua index d97d00832..c01827be4 100644 --- a/frontend/ui/widget/doublespinwidget.lua +++ b/frontend/ui/widget/doublespinwidget.lua @@ -41,6 +41,9 @@ local DoubleSpinWidget = InputContainer:new{ right_text = _("Right"), cancel_text = _("Close"), ok_text = _("Apply"), + cancel_callback = nil, + callback = nil, + close_callback = nil, keep_shown_on_apply = false, -- Set this to add default button that restores numbers to their default values default_values = nil, @@ -187,6 +190,9 @@ function DoubleSpinWidget:update() { text = self.cancel_text, callback = function() + if self.cancel_callback then + self.cancel_callback() + end self:onClose() end, }, @@ -312,7 +318,7 @@ function DoubleSpinWidget:onShow() end function DoubleSpinWidget:onAnyKeyPressed() - UIManager:close(self) + self:onClose() return true end @@ -325,6 +331,9 @@ end function DoubleSpinWidget:onClose() UIManager:close(self) + if self.close_callback then + self.close_callback() + end return true end diff --git a/frontend/ui/widget/infomessage.lua b/frontend/ui/widget/infomessage.lua index ac6d2691b..e35f0414d 100644 --- a/frontend/ui/widget/infomessage.lua +++ b/frontend/ui/widget/infomessage.lua @@ -60,7 +60,7 @@ local InfoMessage = InputContainer:new{ show_icon = true, icon = "notice-info", alpha = nil, -- if image or icon have an alpha channel (default to true for icons, false for images - dismiss_callback = function() end, + dismiss_callback = nil, -- In case we'd like to use it to display some text we know a few more things about: lang = nil, para_direction_rtl = nil, @@ -236,7 +236,15 @@ function InfoMessage:onShow() end -- schedule us to close ourself if timeout provided if self.timeout then - UIManager:scheduleIn(self.timeout, function() UIManager:close(self) end) + UIManager:scheduleIn(self.timeout, function() + -- In case we're provided with dismiss_callback, also call it + -- on timeout + if self.dismiss_callback then + self.dismiss_callback() + self.dismiss_callback = nil + end + UIManager:close(self) + end) end return true end @@ -259,7 +267,10 @@ function InfoMessage:dismiss() UIManager:unschedule(self._delayed_show_action) self._delayed_show_action = nil end - self.dismiss_callback() + if self.dismiss_callback then + self.dismiss_callback() + self.dismiss_callback = nil + end UIManager:close(self) end diff --git a/frontend/ui/widget/spinwidget.lua b/frontend/ui/widget/spinwidget.lua index 23f3d6dbe..2c8e9b709 100644 --- a/frontend/ui/widget/spinwidget.lua +++ b/frontend/ui/widget/spinwidget.lua @@ -37,6 +37,9 @@ local SpinWidget = InputContainer:new{ value_hold_step = 4, cancel_text = _("Close"), ok_text = _("Apply"), + cancel_callback = nil, + callback = nil, + close_callback = nil, keep_shown_on_apply = false, -- Set this to add default button that restores number to its default value default_value = nil, @@ -130,8 +133,7 @@ function SpinWidget:update() text = self.cancel_text, callback = function() if self.cancel_callback then - self.value = value_widget:getValue() - self:cancel_callback(self) + self.cancel_callback() end self:onClose() end, @@ -141,7 +143,7 @@ function SpinWidget:update() callback = function() if self.callback then self.value, self.value_index = value_widget:getValue() - self:callback(self) + self.callback(self) end if not self.keep_shown_on_apply then self:onClose() @@ -266,7 +268,7 @@ function SpinWidget:onShow() end function SpinWidget:onAnyKeyPressed() - UIManager:close(self) + self:onClose() return true end @@ -279,6 +281,9 @@ end function SpinWidget:onClose() UIManager:close(self) + if self.close_callback then + self.close_callback() + end return true end diff --git a/frontend/ui/widget/toggleswitch.lua b/frontend/ui/widget/toggleswitch.lua index f5fb85340..e134b0916 100644 --- a/frontend/ui/widget/toggleswitch.lua +++ b/frontend/ui/widget/toggleswitch.lua @@ -218,7 +218,7 @@ function ToggleSwitch:onTapSelect(arg, gev) end if self.toggle[self.position] ~= "⋮" then self.config:onConfigChoose(self.values, self.name, - self.event, self.args, self.events, self.position, self.delay_repaint) + self.event, self.args, self.events, self.position, self.hide_on_apply) UIManager:setDirty(self.config, function() return "ui", self.dimen end)