Simplify click detection
This commit is contained in:
parent
db1e3916bc
commit
6e95fe9007
@ -186,7 +186,7 @@ function Element:redraw()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Element:handleEvent(evt)
|
function Element:handleEvent(evt)
|
||||||
if Event.isClickEvent(evt) and self.onClick ~= nil then
|
if Event.isClickEvent(evt) and self.onClick ~= nil and Event.containsClick(self, evt, 0, 0) then
|
||||||
local x, y, source = Event.getClickParams(evt)
|
local x, y, source = Event.getClickParams(evt)
|
||||||
return not not self.onClick(self, x, y, source)
|
return not not self.onClick(self, x, y, source)
|
||||||
end
|
end
|
||||||
|
11
gfx/list.lua
11
gfx/list.lua
@ -135,8 +135,8 @@ function List:handleEvent(evt)
|
|||||||
local wOffset = 0
|
local wOffset = 0
|
||||||
local hOffset = 0
|
local hOffset = 0
|
||||||
for _,child in ipairs(self.children) do
|
for _,child in ipairs(self.children) do
|
||||||
if Event.containsClick(child, evt, -wOffset, -hOffset) then
|
if child:handleEvent({Event.repositionEvent(evt, -wOffset, -hOffset)}) then
|
||||||
return child:handleEvent({Event.repositionEvent(evt, -wOffset, -hOffset)})
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if self:isVertical() then
|
if self:isVertical() then
|
||||||
@ -147,11 +147,12 @@ function List:handleEvent(evt)
|
|||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
local handled = false
|
|
||||||
for _,child in ipairs(self.children) do
|
for _,child in ipairs(self.children) do
|
||||||
handled = child:handleEvent(evt) or handled
|
if child:handleEvent(evt) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return handled
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -86,9 +86,7 @@ function Padding:handleEvent(evt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if Event.isClickEvent(evt) then
|
if Event.isClickEvent(evt) then
|
||||||
if Event.containsClick(self.element, evt, -self:getPaddingLeft(), -self:getPaddingTop()) then
|
return self.element:handleEvent({Event.repositionEvent(evt, -self:getPaddingLeft(), -self:getPaddingTop())})
|
||||||
self.element:handleEvent({Event.repositionEvent(evt, -self:getPaddingLeft(), -self:getPaddingTop())})
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
return self.element:handleEvent(evt)
|
return self.element:handleEvent(evt)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user