Simplify event handling

This commit is contained in:
Gabriel Tofvesson 2024-10-08 16:59:32 +02:00
parent df8f9d4018
commit 8232f116a5
3 changed files with 4 additions and 4 deletions

View File

@ -18,8 +18,8 @@ end
function Event.containsClick(element, evt, dX, dY) function Event.containsClick(element, evt, dX, dY)
local x, y = Event.getClickParams(evt) local x, y = Event.getClickParams(evt)
x = x + dX x = x + (dX or 0)
y = y + dY y = y + (dY or 0)
local eX, eY = element:getPos() local eX, eY = element:getPos()
return x >= eX and x < (eX + element:getWidth()) and y >= eY and y < (eY + element:getHeight()) return x >= eX and x < (eX + element:getWidth()) and y >= eY and y < (eY + element:getHeight())
end end

View File

@ -133,7 +133,7 @@ function List:handleEvent(evt)
if Event.isClickEvent(evt) then if Event.isClickEvent(evt) then
-- If click is not inside list bounds, we can safely ignore it -- If click is not inside list bounds, we can safely ignore it
if not Event.containsClick(self, evt, 0, 0) then if not Event.containsClick(self, evt) then
return false return false
end end

View File

@ -86,7 +86,7 @@ function Padding:handleEvent(evt)
end end
if Event.isClickEvent(evt) then if Event.isClickEvent(evt) then
return self.element:handleEvent({Event.repositionEvent(evt, -self:getPaddingLeft(), -self:getPaddingTop())}) return Event.containsClick(self, evt) and self.element:handleEvent({Event.repositionEvent(evt, -self:getPaddingLeft(), -self:getPaddingTop())})
else else
return self.element:handleEvent(evt) return self.element:handleEvent(evt)
end end