From ace3f0ee160f8a09e058f8f32cc537b89165e269 Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Fri, 13 Aug 2021 01:45:10 +0300 Subject: [PATCH] ConfirmBox: new properties (#8065) * keep_dialog_open, default to false. Set to true to keep dialog open upon pressing any button, except Cancel and dismissable tap. * other_buttons_first, default to false. Set to true to put other buttons above Cancel - OK row --- frontend/ui/widget/confirmbox.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/frontend/ui/widget/confirmbox.lua b/frontend/ui/widget/confirmbox.lua index 8a9e16584..409abbf2e 100644 --- a/frontend/ui/widget/confirmbox.lua +++ b/frontend/ui/widget/confirmbox.lua @@ -41,6 +41,7 @@ local Screen = Device.screen local ConfirmBox = InputContainer:new{ modal = true, + keep_dialog_open = false, text = _("no text"), face = Font:getFace("infofont"), ok_text = _("OK"), @@ -48,6 +49,7 @@ local ConfirmBox = InputContainer:new{ ok_callback = function() end, cancel_callback = function() end, other_buttons = nil, + other_buttons_first = false, -- set to true to place other buttons above Cancel-OK row margin = Size.margin.default, padding = Size.padding.default, dismissable = true, -- set to false if any button callback is required @@ -99,6 +101,7 @@ function ConfirmBox:init() text = self.ok_text, callback = function() self.ok_callback() + if self.keep_dialog_open then return end UIManager:close(self) end, },} @@ -106,18 +109,18 @@ function ConfirmBox:init() if self.other_buttons ~= nil then -- additional rows - for __, buttons_row in ipairs(self.other_buttons) do + local rownum = self.other_buttons_first and 0 or 1 + for i, buttons_row in ipairs(self.other_buttons) do local row = {} - table.insert(buttons, row) + table.insert(buttons, rownum + i, row) for ___, button in ipairs(buttons_row) do - assert(type(button.text) == "string") - assert(button.callback == nil or type(button.callback) == "function") table.insert(row, { text = button.text, callback = function() if button.callback ~= nil then button.callback() end + if self.keep_dialog_open then return end UIManager:close(self) end, })