2
0
mirror of https://github.com/koreader/koreader synced 2024-11-16 06:12:56 +00:00

add iconbutton widget

This commit is contained in:
Qingping Hou 2013-03-14 10:52:09 +08:00
parent c94767d9d6
commit b4c5f28164
2 changed files with 54 additions and 1 deletions

View File

@ -2,7 +2,7 @@ require "ui/widget/container"
--[[ --[[
a button widget a button widget
]] --]]
Button = InputContainer:new{ Button = InputContainer:new{
text = nil, -- mandatory text = nil, -- mandatory
preselect = false, preselect = false,

View File

@ -0,0 +1,53 @@
require "ui/widget/container"
require "ui/widget/image"
--[[
Button with a big icon image! Designed for touch device
--]]
IconButton = InputContainer:new{
icon_file = "resources/info-confirm.png",
dimen = nil,
-- parent is used for UIManager:setDirty
parent = nil,
callback = function() end,
}
function IconButton:init()
self.image = ImageWidget:new{
file = self.icon_file
}
self.parent = self.parent or self
self.dimen = self.image:getSize()
self:initGesListener()
self[1] = self.image
end
function IconButton:initGesListener()
self.ges_events = {
TapClickButton = {
GestureRange:new{
ges = "tap",
range = self.dimen,
}
},
}
end
function IconButton:onTapClickButton()
self.image.invert = true
UIManager:setDirty(self.parent, "partial")
UIManager:scheduleIn(0.5, function()
self.image.invert = false
UIManager:setDirty(self.parent, "partial")
end)
self.callback()
end
function IconButton:onSetDimensions(new_dimen)
self.dimen = new_dimen
end