From ecc1f5a84f37a7a768015d72795c26f78741814a Mon Sep 17 00:00:00 2001 From: Paul Liverman III Date: Tue, 18 Apr 2017 23:03:24 -0700 Subject: [PATCH] fix #54 event-handlers require explicit false to fail event handling --- init.lua | 20 ++++++++------------ init.moon | 10 ++++++---- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/init.lua b/init.lua index 34e6871..4ece8b3 100644 --- a/init.lua +++ b/init.lua @@ -239,19 +239,15 @@ 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 - return handled - end + handled = pop.mousepressed(x, y, button, element.child[i]) + if handled ~= false then + return handled end end if element.mousepressed then - do - handled = element:mousepressed(x - element.data.x, y - element.data.y, button) - if handled then - pop.focused = element - end + handled = element:mousepressed(x - element.data.x, y - element.data.y, button) + if handled ~= false then + pop.focused = element end end end @@ -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 diff --git a/init.moon b/init.moon index 2f5b3e7..30bfb14 100644 --- a/init.moon +++ b/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.)