mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
ConfirmBox: add widgets (#10364)
This commit is contained in:
@@ -1136,15 +1136,16 @@ function ReaderBookmark:onSearchBookmark(bm_menu)
|
||||
parent = input_dialog,
|
||||
}
|
||||
input_dialog:addWidget(check_button_case)
|
||||
local separator_width = input_dialog:getAddedWidgetAvailableWidth()
|
||||
separator = CenterContainer:new{
|
||||
dimen = Geom:new{
|
||||
w = input_dialog._input_widget.width,
|
||||
w = separator_width,
|
||||
h = 2 * Size.span.vertical_large,
|
||||
},
|
||||
LineWidget:new{
|
||||
background = Blitbuffer.COLOR_DARK_GRAY,
|
||||
dimen = Geom:new{
|
||||
w = input_dialog._input_widget.width,
|
||||
w = separator_width,
|
||||
h = Size.line.medium,
|
||||
}
|
||||
},
|
||||
|
||||
@@ -38,8 +38,8 @@ local CheckButton = InputContainer:extend{
|
||||
background = Blitbuffer.COLOR_WHITE,
|
||||
text = nil,
|
||||
parent = nil, -- parent widget, must be set by the caller
|
||||
width = nil, -- default value: parent widget's input widget width
|
||||
-- If the parent widget has no input widget, the width must be set by the caller.
|
||||
width = nil, -- default value: parent widget's added widgets available width
|
||||
-- If the parent widget has no getAddedWidgetAvailableWidth() method, the width must be set by the caller.
|
||||
}
|
||||
|
||||
function CheckButton:init()
|
||||
@@ -70,7 +70,7 @@ function CheckButton:initCheckButton(checked)
|
||||
self._textwidget = TextBoxWidget:new{
|
||||
text = self.text,
|
||||
face = self.face,
|
||||
width = (self.width or self.parent._input_widget.width) - self._checkmark.dimen.w,
|
||||
width = (self.width or self.parent:getAddedWidgetAvailableWidth()) - self._checkmark.dimen.w,
|
||||
fgcolor = self.enabled and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_DARK_GRAY,
|
||||
}
|
||||
local textbox_shift = math.max(0, self._checkmark.baseline - self._textwidget:getBaseline())
|
||||
|
||||
@@ -76,11 +76,23 @@ function ConfirmBox:init()
|
||||
self.key_events.Close = { { Device.input.group.Back } }
|
||||
end
|
||||
end
|
||||
|
||||
self.text_widget_width = math.floor(math.min(Screen:getWidth(), Screen:getHeight()) * 2/3)
|
||||
local text_widget = TextBoxWidget:new{
|
||||
text = self.text,
|
||||
face = self.face,
|
||||
width = math.floor(math.min(Screen:getWidth(), Screen:getHeight()) * 2/3),
|
||||
width = self.text_widget_width,
|
||||
}
|
||||
self.text_group = VerticalGroup:new{
|
||||
align = "left",
|
||||
text_widget,
|
||||
}
|
||||
if self._added_widgets then
|
||||
table.insert(self.text_group, VerticalSpan:new{ width = Size.padding.large })
|
||||
for _, widget in ipairs(self._added_widgets) do
|
||||
table.insert(self.text_group, widget)
|
||||
end
|
||||
end
|
||||
local content = HorizontalGroup:new{
|
||||
align = "center",
|
||||
IconWidget:new{
|
||||
@@ -88,36 +100,36 @@ function ConfirmBox:init()
|
||||
alpha = true,
|
||||
},
|
||||
HorizontalSpan:new{ width = Size.span.horizontal_default },
|
||||
text_widget,
|
||||
self.text_group,
|
||||
}
|
||||
|
||||
local buttons = {{
|
||||
text = self.cancel_text,
|
||||
callback = function()
|
||||
self.cancel_callback()
|
||||
UIManager:close(self)
|
||||
end,
|
||||
}, {
|
||||
text = self.ok_text,
|
||||
callback = function()
|
||||
self.ok_callback()
|
||||
if self.keep_dialog_open then return end
|
||||
UIManager:close(self)
|
||||
end,
|
||||
},}
|
||||
buttons = { buttons } -- single row
|
||||
local buttons = {{ -- single row
|
||||
{
|
||||
text = self.cancel_text,
|
||||
callback = function()
|
||||
self.cancel_callback()
|
||||
UIManager:close(self)
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = self.ok_text,
|
||||
callback = function()
|
||||
self.ok_callback()
|
||||
if self.keep_dialog_open then return end
|
||||
UIManager:close(self)
|
||||
end,
|
||||
},
|
||||
}}
|
||||
|
||||
if self.other_buttons ~= nil then
|
||||
-- additional rows
|
||||
if self.other_buttons then -- additional rows
|
||||
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, rownum + i, row)
|
||||
for ___, button in ipairs(buttons_row) do
|
||||
for _, button in ipairs(buttons_row) do
|
||||
table.insert(row, {
|
||||
text = button.text,
|
||||
callback = function()
|
||||
if button.callback ~= nil then
|
||||
if button.callback then
|
||||
button.callback()
|
||||
end
|
||||
if self.keep_dialog_open then return end
|
||||
@@ -125,13 +137,12 @@ function ConfirmBox:init()
|
||||
end,
|
||||
})
|
||||
end
|
||||
table.insert(buttons, rownum + i, row)
|
||||
end
|
||||
end
|
||||
|
||||
local button_table = ButtonTable:new{
|
||||
width = content:getSize().w,
|
||||
button_font_face = "cfont",
|
||||
button_font_size = 20,
|
||||
buttons = buttons,
|
||||
zero_sep = true,
|
||||
show_parent = self,
|
||||
@@ -177,12 +188,37 @@ function ConfirmBox:init()
|
||||
end
|
||||
end
|
||||
-- re-init this widget
|
||||
if self._added_widgets then
|
||||
self:_preserveAddedWidgets()
|
||||
end
|
||||
self:free()
|
||||
self:init()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ConfirmBox:addWidget(widget)
|
||||
if self._added_widgets then
|
||||
self:_preserveAddedWidgets()
|
||||
else
|
||||
self._added_widgets = {}
|
||||
end
|
||||
table.insert(self._added_widgets, widget)
|
||||
self:free()
|
||||
self:init()
|
||||
end
|
||||
|
||||
function ConfirmBox:_preserveAddedWidgets()
|
||||
-- remove added widgets to preserve their subwidgets from being free'ed
|
||||
for i = 1, #self._added_widgets do
|
||||
table.remove(self.text_group)
|
||||
end
|
||||
end
|
||||
|
||||
function ConfirmBox:getAddedWidgetAvailableWidth()
|
||||
return self.text_widget_width
|
||||
end
|
||||
|
||||
function ConfirmBox:onShow()
|
||||
UIManager:setDirty(self, function()
|
||||
return "ui", self.movable.dimen
|
||||
|
||||
@@ -469,6 +469,10 @@ function InputDialog:addWidget(widget, re_init)
|
||||
table.insert(self.vgroup, #self.vgroup-1, widget)
|
||||
end
|
||||
|
||||
function InputDialog:getAddedWidgetAvailableWidth()
|
||||
return self._input_widget.width
|
||||
end
|
||||
|
||||
function InputDialog:onTap()
|
||||
if self.deny_keyboard_hiding then
|
||||
return
|
||||
|
||||
@@ -43,7 +43,6 @@ function OpenWithDialog:init()
|
||||
}
|
||||
self.layout = {self.layout[#self.layout]} -- keep bottom buttons
|
||||
self:mergeLayoutInVertical(self.radio_button_table, #self.layout) -- before bottom buttons
|
||||
self._input_widget = self.radio_button_table
|
||||
|
||||
local vertical_span = VerticalSpan:new{
|
||||
width = Size.padding.large,
|
||||
|
||||
Reference in New Issue
Block a user