mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
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
This commit is contained in:
@@ -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,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user