2013-10-18 20:38:07 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
2014-09-05 13:06:58 +00:00
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
2013-10-18 20:38:07 +00:00
|
|
|
local ButtonTable = require("ui/widget/buttontable")
|
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
|
|
|
local LineWidget = require("ui/widget/linewidget")
|
|
|
|
local InputText = require("ui/widget/inputtext")
|
2014-09-05 13:06:58 +00:00
|
|
|
local RenderText = require("ui/rendertext")
|
2013-10-18 20:38:07 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Screen = require("device").screen
|
2014-09-05 13:06:58 +00:00
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local Font = require("ui/font")
|
2014-10-22 13:34:11 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
2013-07-30 15:07:33 +00:00
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local InputDialog = InputContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
title = "",
|
|
|
|
input = "",
|
|
|
|
input_hint = "",
|
|
|
|
buttons = nil,
|
|
|
|
input_type = nil,
|
|
|
|
enter_callback = nil,
|
2014-04-23 14:19:29 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
width = nil,
|
|
|
|
height = nil,
|
2014-04-23 14:19:29 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
title_face = Font:getFace("tfont", 22),
|
|
|
|
input_face = Font:getFace("cfont", 20),
|
2014-04-23 14:19:29 +00:00
|
|
|
|
2014-11-20 22:07:39 +00:00
|
|
|
title_padding = Screen:scaleBySize(5),
|
|
|
|
title_margin = Screen:scaleBySize(2),
|
|
|
|
input_padding = Screen:scaleBySize(10),
|
|
|
|
input_margin = Screen:scaleBySize(10),
|
|
|
|
button_padding = Screen:scaleBySize(14),
|
2013-07-30 15:07:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function InputDialog:init()
|
2014-09-05 13:06:58 +00:00
|
|
|
local title_width = RenderText:sizeUtf8Text(0, self.width,
|
|
|
|
self.title_face, self.title, true).x
|
|
|
|
if title_width > self.width then
|
|
|
|
local indicator = " >> "
|
|
|
|
local indicator_w = RenderText:sizeUtf8Text(0, self.width,
|
|
|
|
self.title_face, indicator, true).x
|
|
|
|
self.title = RenderText:getSubTextByWidth(self.title, self.title_face,
|
|
|
|
self.width - indicator_w, true) .. indicator
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
self.title = FrameContainer:new{
|
|
|
|
padding = self.title_padding,
|
|
|
|
margin = self.title_margin,
|
|
|
|
bordersize = 0,
|
|
|
|
TextWidget:new{
|
|
|
|
text = self.title,
|
|
|
|
face = self.title_face,
|
|
|
|
width = self.width,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.input = InputText:new{
|
|
|
|
text = self.input,
|
|
|
|
hint = self.input_hint,
|
|
|
|
face = self.input_face,
|
|
|
|
width = self.width * 0.9,
|
|
|
|
input_type = self.input_type,
|
|
|
|
enter_callback = self.enter_callback,
|
|
|
|
scroll = false,
|
|
|
|
parent = self,
|
|
|
|
}
|
2014-04-23 14:19:29 +00:00
|
|
|
self.button_table = ButtonTable:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
width = self.width,
|
|
|
|
button_font_face = "cfont",
|
|
|
|
button_font_size = 20,
|
|
|
|
buttons = self.buttons,
|
|
|
|
zero_sep = true,
|
2014-05-01 10:37:12 +00:00
|
|
|
show_parent = self,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2014-04-23 14:19:29 +00:00
|
|
|
self.title_bar = LineWidget:new{
|
2014-10-22 13:34:11 +00:00
|
|
|
--background = Blitbuffer.gray(0.5),
|
2014-03-13 13:52:43 +00:00
|
|
|
dimen = Geom:new{
|
2014-04-23 14:19:29 +00:00
|
|
|
w = self.button_table:getSize().w + self.button_padding,
|
2014-11-20 22:07:39 +00:00
|
|
|
h = Screen:scaleBySize(2),
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-23 14:19:29 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self.dialog_frame = FrameContainer:new{
|
|
|
|
radius = 8,
|
|
|
|
bordersize = 3,
|
|
|
|
padding = 0,
|
|
|
|
margin = 0,
|
2014-10-22 13:34:11 +00:00
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
2014-03-13 13:52:43 +00:00
|
|
|
VerticalGroup:new{
|
|
|
|
align = "left",
|
|
|
|
self.title,
|
2014-04-23 14:19:29 +00:00
|
|
|
self.title_bar,
|
2014-03-13 13:52:43 +00:00
|
|
|
-- input
|
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
2014-04-23 14:19:29 +00:00
|
|
|
w = self.title_bar:getSize().w,
|
2014-03-13 13:52:43 +00:00
|
|
|
h = self.input:getSize().h,
|
|
|
|
},
|
|
|
|
self.input,
|
|
|
|
},
|
|
|
|
-- buttons
|
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
2014-04-23 14:19:29 +00:00
|
|
|
w = self.title_bar:getSize().w,
|
|
|
|
h = self.button_table:getSize().h,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2014-04-23 14:19:29 +00:00
|
|
|
self.button_table,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-23 14:19:29 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self[1] = CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight() - self.input:getKeyboardDimen().h,
|
|
|
|
},
|
|
|
|
self.dialog_frame,
|
|
|
|
}
|
2014-12-01 14:39:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function InputDialog:onShow()
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
return "partial", self.dialog_frame.dimen
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
function InputDialog:onCloseWidget()
|
|
|
|
UIManager:setDirty(nil, function()
|
|
|
|
return "partial", self.dialog_frame.dimen
|
|
|
|
end)
|
2013-07-30 15:07:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function InputDialog:onShowKeyboard()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.input:onShowKeyboard()
|
2013-07-30 15:07:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function InputDialog:getInputText()
|
2014-03-13 13:52:43 +00:00
|
|
|
return self.input:getText()
|
2013-07-30 15:07:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function InputDialog:onClose()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.input:onCloseKeyboard()
|
2013-07-30 15:07:33 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
|
|
|
return InputDialog
|