SpinWidget buttons move (#8485)

SpinWidget "Default value" and extra buttons move up.
Cancel/OK buttons row is in the bottom now.
Default value is shown in the Default button.
This commit is contained in:
hius07
2021-11-27 19:10:54 +02:00
committed by GitHub
parent 56d54d2c1a
commit 372dd9e36b

View File

@@ -19,6 +19,7 @@ local VerticalGroup = require("ui/widget/verticalgroup")
local WidgetContainer = require("ui/widget/container/widgetcontainer")
local _ = require("gettext")
local Screen = Device.screen
local T = require("ffi/util").template
local SpinWidget = InputContainer:new{
title_text = "",
@@ -30,20 +31,22 @@ local SpinWidget = InputContainer:new{
value_table = nil,
value_index = nil,
value = 1,
value_max = 20,
value_min = 0,
value_max = 20,
value_step = 1,
value_hold_step = 4,
precision = nil, -- default "%02d" in NumberPickerWidget
wrap = false,
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
-- Set this to add upper default button that restores number to its default value
default_value = nil,
default_text = _("Use default"),
-- Optional extra button on bottom
default_text = nil,
-- Optional extra button above ok/cancel buttons row
extra_text = nil,
extra_callback = nil,
}
@@ -91,7 +94,7 @@ function SpinWidget:update()
value_step = self.value_step,
value_hold_step = self.value_hold_step,
precision = self.precision,
wrap = self.wrap or false,
wrap = self.wrap,
}
local value_group = HorizontalGroup:new{
align = "center",
@@ -114,36 +117,13 @@ function SpinWidget:update()
h = Size.line.thick,
}
}
local buttons = {
{
{
text = self.cancel_text,
callback = function()
if self.cancel_callback then
self.cancel_callback()
end
self:onClose()
end,
},
{
text = self.ok_text,
callback = function()
if self.callback then
self.value, self.value_index = value_widget:getValue()
self.callback(self)
end
if not self.keep_shown_on_apply then
self:onClose()
end
end,
},
}
}
local buttons = {}
if self.default_value then
table.insert(buttons,{
table.insert(buttons, {
{
text = self.default_text,
text = self.default_text or T(_("Default value: %1"),
self.precision and string.format(self.precision, self.default_value) or self.default_value),
callback = function()
value_widget.value = self.default_value
value_widget:update()
@@ -152,7 +132,7 @@ function SpinWidget:update()
})
end
if self.extra_text then
table.insert(buttons,{
table.insert(buttons, {
{
text = self.extra_text,
callback = function()
@@ -167,6 +147,29 @@ function SpinWidget:update()
},
})
end
table.insert(buttons, {
{
text = self.cancel_text,
callback = function()
if self.cancel_callback then
self.cancel_callback()
end
self:onClose()
end,
},
{
text = self.ok_text,
callback = function()
if self.callback then
self.value, self.value_index = value_widget:getValue()
self.callback(self)
end
if not self.keep_shown_on_apply then
self:onClose()
end
end,
},
})
local ok_cancel_buttons = ButtonTable:new{
width = self.width - 2*Size.padding.default,