From cb037bf81174b8594e773e73ca54dcf9e1e3a193 Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Tue, 8 Oct 2024 17:27:08 +0200 Subject: [PATCH] Fix offset calculations --- gfx/element.lua | 11 ++++------- gfx/list.lua | 3 ++- gfx/padding.lua | 4 +++- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/gfx/element.lua b/gfx/element.lua index 1d3e143..9494c27 100644 --- a/gfx/element.lua +++ b/gfx/element.lua @@ -186,13 +186,10 @@ function Element:redraw() end function Element:handleEvent(evt) - if Event.isClickEvent(evt) and Event.containsClick(self, evt) then - if self.onClick ~= nil then - local x, y, source = Event.getClickParams(evt) - return not not self.onClick(self, x, y, source) - else - return false - end + evt = Event.repositionEvent(evt, 1 - self:getX(), 1 - self:getY()) + if Event.isClickEvent(evt) and Event.containsClick(self, evt) and self.onClick ~= nil then + local x, y, source = Event.getClickParams(evt) + return not not self.onClick(self, x, y, source) end return false end diff --git a/gfx/list.lua b/gfx/list.lua index e42942d..641582c 100644 --- a/gfx/list.lua +++ b/gfx/list.lua @@ -127,6 +127,7 @@ function List:findById(id) end function List:handleEvent(evt) + evt = Event.repositionEvent(evt, 1 - self:getX(), 1 - self:getY()) if Element.handleEvent(self, evt) then return true end @@ -140,7 +141,7 @@ function List:handleEvent(evt) local wOffset = 0 local hOffset = 0 for _,child in ipairs(self.children) do - if child:handleEvent({Event.repositionEvent(evt, -wOffset, -hOffset)}) then + if child:handleEvent(evt) then return true end diff --git a/gfx/padding.lua b/gfx/padding.lua index b907568..88078ac 100644 --- a/gfx/padding.lua +++ b/gfx/padding.lua @@ -81,12 +81,14 @@ function Padding:findById(id) end function Padding:handleEvent(evt) + evt = Event.repositionEvent(evt, 1 - self:getX(), 1 - self:getY()) + if Element.handleEvent(self, evt) then return true end if Event.isClickEvent(evt) then - return Event.containsClick(self, evt) and self.element:handleEvent({Event.repositionEvent(evt, -self:getPaddingLeft(), -self:getPaddingTop())}) + return Event.containsClick(self, evt) and self.element:handleEvent(evt) else return self.element:handleEvent(evt) end