2017-09-14 20:31:25 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
2014-08-25 16:00:11 +00:00
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
2017-09-14 20:31:25 +00:00
|
|
|
local Device = require("device")
|
|
|
|
local Font = require("ui/font")
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
local Geom = require("ui/geometry")
|
2014-08-25 16:00:11 +00:00
|
|
|
local InputDialog = require("ui/widget/inputdialog")
|
|
|
|
local InputText = require("ui/widget/inputtext")
|
2017-09-13 14:56:20 +00:00
|
|
|
local Size = require("ui/size")
|
2017-09-14 20:31:25 +00:00
|
|
|
local TextBoxWidget = require("ui/widget/textboxwidget")
|
2014-08-25 16:00:11 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2017-09-14 20:31:25 +00:00
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
2017-10-08 15:53:25 +00:00
|
|
|
local VerticalSpan = require("ui/widget/verticalspan")
|
2014-08-25 16:00:11 +00:00
|
|
|
local _ = require("gettext")
|
2017-09-14 20:31:25 +00:00
|
|
|
local Screen = Device.screen
|
2014-08-25 16:00:11 +00:00
|
|
|
|
2017-09-14 20:31:25 +00:00
|
|
|
local input_field, input_description
|
2014-08-25 16:00:11 +00:00
|
|
|
|
|
|
|
local MultiInputDialog = InputDialog:extend{
|
|
|
|
field = {},
|
|
|
|
field_hint = {},
|
2014-09-05 13:05:20 +00:00
|
|
|
fields = {},
|
2017-09-13 14:56:20 +00:00
|
|
|
description_padding = Size.padding.default,
|
|
|
|
description_margin = Size.margin.small,
|
2014-08-25 16:00:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function MultiInputDialog:init()
|
|
|
|
-- init title and buttons in base class
|
|
|
|
InputDialog.init(self)
|
|
|
|
local VerticalGroupData = VerticalGroup:new{
|
|
|
|
align = "left",
|
|
|
|
self.title,
|
|
|
|
self.title_bar,
|
|
|
|
}
|
|
|
|
|
|
|
|
input_field = {}
|
2017-09-14 20:31:25 +00:00
|
|
|
input_description = {}
|
2014-08-25 16:00:11 +00:00
|
|
|
local k = 0
|
2014-09-05 13:05:20 +00:00
|
|
|
for i, field in ipairs(self.fields) do
|
2014-08-25 16:00:11 +00:00
|
|
|
k = k + 1
|
|
|
|
input_field[k] = InputText:new{
|
2014-09-05 13:05:20 +00:00
|
|
|
text = field.text or "",
|
|
|
|
hint = field.hint or "",
|
2015-09-07 17:06:17 +00:00
|
|
|
input_type = field.input_type or "string",
|
2014-08-25 16:00:11 +00:00
|
|
|
face = self.input_face,
|
|
|
|
width = self.width * 0.9,
|
2014-09-05 13:05:20 +00:00
|
|
|
focused = k == 1 and true or false,
|
2014-08-25 16:00:11 +00:00
|
|
|
scroll = false,
|
|
|
|
parent = self,
|
2018-07-07 22:45:27 +00:00
|
|
|
padding = field.padding or nil,
|
|
|
|
margin = field.margin or nil,
|
2014-08-25 16:00:11 +00:00
|
|
|
}
|
2018-03-30 10:46:36 +00:00
|
|
|
if Device:hasKeys() then
|
|
|
|
--little hack to piggyback on the layout of the button_table to handle the new InputText
|
|
|
|
table.insert(self.button_table.layout, #self.button_table.layout, {input_field[k]})
|
|
|
|
end
|
2017-09-14 20:31:25 +00:00
|
|
|
if field.description then
|
|
|
|
input_description[k] = FrameContainer:new{
|
|
|
|
padding = self.description_padding,
|
|
|
|
margin = self.description_margin,
|
|
|
|
bordersize = 0,
|
|
|
|
TextBoxWidget:new{
|
|
|
|
text = field.description,
|
|
|
|
face = Font:getFace("x_smallinfofont"),
|
|
|
|
width = self.width * 0.9,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
table.insert(VerticalGroupData, CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.title_bar:getSize().w,
|
|
|
|
h = input_description[k]:getSize().h ,
|
|
|
|
},
|
|
|
|
input_description[k],
|
|
|
|
})
|
|
|
|
end
|
2016-05-02 02:39:31 +00:00
|
|
|
table.insert(VerticalGroupData, CenterContainer:new{
|
2014-08-25 16:00:11 +00:00
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.title_bar:getSize().w,
|
|
|
|
h = input_field[k]:getSize().h,
|
|
|
|
},
|
|
|
|
input_field[k],
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2018-03-30 10:46:36 +00:00
|
|
|
if Device:hasKeys() then
|
|
|
|
--remove the not needed hack in inputdialog
|
|
|
|
table.remove(self.button_table.layout, 1)
|
|
|
|
end
|
2017-10-08 15:53:25 +00:00
|
|
|
-- Add same vertical space after than before InputText
|
|
|
|
table.insert(VerticalGroupData,CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.title_bar:getSize().w,
|
|
|
|
h = self.description_padding + self.description_margin,
|
|
|
|
},
|
|
|
|
VerticalSpan:new{ width = self.description_padding + self.description_margin },
|
|
|
|
})
|
2014-08-25 16:00:11 +00:00
|
|
|
-- buttons
|
|
|
|
table.insert(VerticalGroupData,CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.title_bar:getSize().w,
|
|
|
|
h = self.button_table:getSize().h,
|
|
|
|
},
|
|
|
|
self.button_table,
|
|
|
|
})
|
|
|
|
|
|
|
|
self.dialog_frame = FrameContainer:new{
|
2017-09-13 14:56:20 +00:00
|
|
|
radius = Size.radius.window,
|
|
|
|
bordersize = Size.border.window,
|
2014-08-25 16:00:11 +00:00
|
|
|
padding = 0,
|
|
|
|
margin = 0,
|
2014-10-22 13:34:11 +00:00
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
2014-08-25 16:00:11 +00:00
|
|
|
VerticalGroupData,
|
|
|
|
}
|
|
|
|
|
2016-02-21 15:30:06 +00:00
|
|
|
self._input_widget = input_field[1]
|
2014-08-25 16:00:11 +00:00
|
|
|
|
|
|
|
self[1] = CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = Screen:getWidth(),
|
2016-02-21 15:30:06 +00:00
|
|
|
h = Screen:getHeight() - self._input_widget:getKeyboardDimen().h,
|
2014-08-25 16:00:11 +00:00
|
|
|
},
|
|
|
|
self.dialog_frame,
|
|
|
|
}
|
2014-11-30 00:12:00 +00:00
|
|
|
UIManager:setDirty("all", "full")
|
2014-08-25 16:00:11 +00:00
|
|
|
end
|
|
|
|
|
2014-09-05 13:05:20 +00:00
|
|
|
function MultiInputDialog:getFields()
|
|
|
|
local fields = {}
|
|
|
|
for i=1, #input_field do
|
|
|
|
table.insert(fields, input_field[i].text)
|
2014-08-25 16:00:11 +00:00
|
|
|
end
|
2014-09-05 13:05:20 +00:00
|
|
|
return fields
|
2014-08-25 16:00:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function MultiInputDialog:onSwitchFocus(inputbox)
|
|
|
|
-- unfocus current inputbox
|
2016-02-21 15:30:06 +00:00
|
|
|
self._input_widget:unfocus()
|
|
|
|
self._input_widget:onCloseKeyboard()
|
2018-07-07 22:45:27 +00:00
|
|
|
UIManager:setDirty(nil, function()
|
|
|
|
return "ui", self.dialog_frame.dimen
|
|
|
|
end)
|
2014-08-25 16:00:11 +00:00
|
|
|
|
|
|
|
-- focus new inputbox
|
2016-02-21 15:30:06 +00:00
|
|
|
self._input_widget = inputbox
|
|
|
|
self._input_widget:focus()
|
|
|
|
self._input_widget:onShowKeyboard()
|
2014-08-25 16:00:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return MultiInputDialog
|
|
|
|
|