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

56 lines
1.1 KiB
Lua
Raw Normal View History

2013-03-14 02:52:09 +00:00
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,
2013-03-15 09:23:39 +00:00
-- show_parent is used for UIManager:setDirty, so we can trigger repaint
show_parent = nil,
2013-03-14 02:52:09 +00:00
callback = function() end,
}
function IconButton:init()
self.image = ImageWidget:new{
file = self.icon_file
}
2013-03-15 09:23:39 +00:00
self.show_parent = self.show_parent or self
2013-03-14 02:52:09 +00:00
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
2013-03-15 09:23:39 +00:00
UIManager:setDirty(self.show_parent, "partial")
2013-03-15 09:18:34 +00:00
-- make sure button reacts before doing callback
UIManager:scheduleIn(0.1, function()
self.callback()
2013-03-14 02:52:09 +00:00
self.image.invert = false
2013-03-15 09:23:39 +00:00
UIManager:setDirty(self.show_parent, "partial")
2013-03-14 02:52:09 +00:00
end)
2013-03-14 03:57:51 +00:00
return true
2013-03-14 02:52:09 +00:00
end
function IconButton:onSetDimensions(new_dimen)
self.dimen = new_dimen
end