Assume element-local coordinates in handler
This commit is contained in:
parent
cb037bf811
commit
a13b2fb208
@ -186,7 +186,6 @@ function Element:redraw()
|
||||
end
|
||||
|
||||
function Element:handleEvent(evt)
|
||||
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)
|
||||
|
@ -16,6 +16,10 @@ function Event.repositionEvent(evt, dX, dY)
|
||||
end
|
||||
end
|
||||
|
||||
function Event.toElementLocalPosition(evt, element)
|
||||
return {Event.repositionEvent(evt, 1 - element:getX(), 1 - element:getY())}
|
||||
end
|
||||
|
||||
function Event.containsClick(element, evt, dX, dY)
|
||||
local x, y = Event.getClickParams(evt)
|
||||
x = x + (dX or 0)
|
||||
|
13
gfx/list.lua
13
gfx/list.lua
@ -127,7 +127,6 @@ 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
|
||||
@ -138,23 +137,15 @@ function List:handleEvent(evt)
|
||||
return false
|
||||
end
|
||||
|
||||
local wOffset = 0
|
||||
local hOffset = 0
|
||||
for _,child in ipairs(self.children) do
|
||||
if child:handleEvent(evt) then
|
||||
if child:handleEvent(Event.toElementLocalPosition(evt, child)) then
|
||||
return true
|
||||
end
|
||||
|
||||
if self:isVertical() then
|
||||
hOffset = hOffset + child:getHeight()
|
||||
else
|
||||
wOffset = wOffset + child:getWidth()
|
||||
end
|
||||
end
|
||||
return false
|
||||
else
|
||||
for _,child in ipairs(self.children) do
|
||||
if child:handleEvent(evt) then
|
||||
if child:handleEvent(Event.toElementLocalPosition(evt, child)) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
@ -81,14 +81,12 @@ 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(evt)
|
||||
return Event.containsClick(self, evt) and self.element:handleEvent(Event.toElementLocalPosition(evt, self.element))
|
||||
else
|
||||
return self.element:handleEvent(evt)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user