|
|
|
@ -1,10 +1,12 @@
|
|
|
|
|
require "ui/widget/image"
|
|
|
|
|
require "ui/widget/container"
|
|
|
|
|
|
|
|
|
|
--[[
|
|
|
|
|
a button widget
|
|
|
|
|
a button widget that shows text or a icon and handles callback when tapped
|
|
|
|
|
--]]
|
|
|
|
|
Button = InputContainer:new{
|
|
|
|
|
text = nil, -- mandatory
|
|
|
|
|
icon = nil,
|
|
|
|
|
preselect = false,
|
|
|
|
|
callback = nil,
|
|
|
|
|
enabled = true,
|
|
|
|
@ -19,15 +21,22 @@ Button = InputContainer:new{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Button:init()
|
|
|
|
|
self.text_widget = TextWidget:new{
|
|
|
|
|
text = self.text,
|
|
|
|
|
bgcolor = 0.0,
|
|
|
|
|
fgcolor = self.enabled and 1.0 or 0.5,
|
|
|
|
|
face = Font:getFace(self.text_font_face, self.text_font_size)
|
|
|
|
|
}
|
|
|
|
|
local text_size = self.text_widget:getSize()
|
|
|
|
|
if self.text then
|
|
|
|
|
self.label_widget = TextWidget:new{
|
|
|
|
|
text = self.text,
|
|
|
|
|
bgcolor = 0.0,
|
|
|
|
|
fgcolor = self.enabled and 1.0 or 0.5,
|
|
|
|
|
face = Font:getFace(self.text_font_face, self.text_font_size)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
self.label_widget = ImageWidget:new{
|
|
|
|
|
file = self.icon,
|
|
|
|
|
dim = self.enabled,
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
local widget_size = self.label_widget:getSize()
|
|
|
|
|
if self.width == nil then
|
|
|
|
|
self.width = text_size.w
|
|
|
|
|
self.width = widget_size.w
|
|
|
|
|
end
|
|
|
|
|
-- set FrameContainer content
|
|
|
|
|
self[1] = FrameContainer:new{
|
|
|
|
@ -39,9 +48,9 @@ function Button:init()
|
|
|
|
|
CenterContainer:new{
|
|
|
|
|
dimen = Geom:new{
|
|
|
|
|
w = self.width,
|
|
|
|
|
h = text_size.h
|
|
|
|
|
h = widget_size.h
|
|
|
|
|
},
|
|
|
|
|
self.text_widget,
|
|
|
|
|
self.label_widget,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if self.preselect then
|
|
|
|
@ -75,12 +84,48 @@ end
|
|
|
|
|
|
|
|
|
|
function Button:enable()
|
|
|
|
|
self.enabled = true
|
|
|
|
|
self.text_widget.fgcolor = 1.0
|
|
|
|
|
if self.text then
|
|
|
|
|
self.label_widget.fgcolor = self.enabled and 1.0 or 0.5
|
|
|
|
|
else
|
|
|
|
|
self.label_widget.dim = not self.enabled
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Button:disable()
|
|
|
|
|
self.enabled = false
|
|
|
|
|
self.text_widget.fgcolor = 0.5
|
|
|
|
|
if self.text then
|
|
|
|
|
self.label_widget.fgcolor = self.enabled and 1.0 or 0.5
|
|
|
|
|
else
|
|
|
|
|
self.label_widget.dim = not self.enabled
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Button:enableDisable(enable)
|
|
|
|
|
if enable then
|
|
|
|
|
self:enable()
|
|
|
|
|
else
|
|
|
|
|
self:disable()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Button:hide()
|
|
|
|
|
if self.icon then
|
|
|
|
|
self.label_widget.hide = true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Button:show()
|
|
|
|
|
if self.icon then
|
|
|
|
|
self.label_widget.hide = false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Button:showHide(show)
|
|
|
|
|
if show then
|
|
|
|
|
self:show()
|
|
|
|
|
else
|
|
|
|
|
self:hide()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Button:onTapSelect()
|
|
|
|
|