mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
fix #54 event-handlers require explicit false to fail event handling
This commit is contained in:
parent
3fb4b15241
commit
ecc1f5a84f
12
init.lua
12
init.lua
@ -239,22 +239,18 @@ pop.mousepressed = function(x, y, button, element)
|
||||
local handled = false
|
||||
if element.data.draw and (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h) then
|
||||
for i = #element.child, 1, -1 do
|
||||
do
|
||||
handled = pop.mousepressed(x, y, button, element.child[i])
|
||||
if handled then
|
||||
if handled ~= false then
|
||||
return handled
|
||||
end
|
||||
end
|
||||
end
|
||||
if element.mousepressed then
|
||||
do
|
||||
handled = element:mousepressed(x - element.data.x, y - element.data.y, button)
|
||||
if handled then
|
||||
if handled ~= false then
|
||||
pop.focused = element
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return handled
|
||||
end
|
||||
pop.mousereleased = function(x, y, button, element)
|
||||
@ -264,7 +260,7 @@ pop.mousereleased = function(x, y, button, element)
|
||||
if element.data.draw and (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h) then
|
||||
for i = #element.child, 1, -1 do
|
||||
clickedHandled, mousereleasedHandled = pop.mousereleased(x, y, button, element.child[i])
|
||||
if clickedHandled or mousereleasedHandled then
|
||||
if clickedHandled ~= false or mousereleasedHandled ~= false then
|
||||
return clickedHandled, mousereleasedHandled
|
||||
end
|
||||
end
|
||||
@ -274,7 +270,7 @@ pop.mousereleased = function(x, y, button, element)
|
||||
if element.mousereleased then
|
||||
mousereleasedHandled = element:mousereleased(x - element.data.x, y - element.data.y, button)
|
||||
end
|
||||
if clickedHandled then
|
||||
if clickedHandled ~= false then
|
||||
pop.focused = element
|
||||
end
|
||||
end
|
||||
|
10
init.moon
10
init.moon
@ -315,12 +315,14 @@ pop.mousepressed = (x, y, button, element) ->
|
||||
if element.data.draw and (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h)
|
||||
-- check its child elements in reverse order, returning if something handles it
|
||||
for i = #element.child, 1, -1
|
||||
if handled = pop.mousepressed x, y, button, element.child[i]
|
||||
handled = pop.mousepressed x, y, button, element.child[i]
|
||||
if handled != false
|
||||
return handled
|
||||
|
||||
-- if a child hasn't handled it yet, try to handle it, and set pop.focused
|
||||
if element.mousepressed
|
||||
if handled = element\mousepressed x - element.data.x, y - element.data.y, button
|
||||
handled = element\mousepressed x - element.data.x, y - element.data.y, button
|
||||
if handled != false
|
||||
pop.focused = element
|
||||
|
||||
-- return whether or not we have handled the event
|
||||
@ -351,7 +353,7 @@ pop.mousereleased = (x, y, button, element) ->
|
||||
-- check its children in reverse for handling a clicked or mousereleased event
|
||||
for i = #element.child, 1, -1
|
||||
clickedHandled, mousereleasedHandled = pop.mousereleased x, y, button, element.child[i]
|
||||
if clickedHandled or mousereleasedHandled
|
||||
if clickedHandled != false or mousereleasedHandled != false
|
||||
return clickedHandled, mousereleasedHandled
|
||||
|
||||
-- if that doesn't work, we try to handle it ourselves
|
||||
@ -361,7 +363,7 @@ pop.mousereleased = (x, y, button, element) ->
|
||||
mousereleasedHandled = element\mousereleased x - element.data.x, y - element.data.y, button
|
||||
|
||||
-- if we clicked, we're focused!
|
||||
if clickedHandled
|
||||
if clickedHandled != false
|
||||
pop.focused = element
|
||||
--- @todo Figure out how to bring a focused element to the front of view (aka the first element in its parent's children).
|
||||
--- (If I do it right here, the for loop above may break! I need to test/figure this out.)
|
||||
|
Loading…
Reference in New Issue
Block a user