about summary refs log tree commit diff stats
path: root/button.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-08-23 11:43:10 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-08-23 11:43:10 -0700
commit468b791050d9aa631871002e4fde70c3ea82bc0c (patch)
tree89a41873822c36eb0e63c118747aeabe7f430a7b /button.lua
parent8057f3e8fe016ea054fa1c878e2c90b5ae32d1b6 (diff)
downloadlines.love-468b791050d9aa631871002e4fde70c3ea82bc0c.tar.gz
flip return value of button handlers
This is compatible with Javascript, and it also seems like a better
default; when people forget to think about return values in click
handlers, they should be consumed.
Diffstat (limited to 'button.lua')
-rw-r--r--button.lua7
1 files changed, 3 insertions, 4 deletions
diff --git a/button.lua b/button.lua
index 4c7fe0b..748f5ae 100644
--- a/button.lua
+++ b/button.lua
@@ -1,7 +1,6 @@
 -- Simple immediate-mode buttons with (currently) just an onpress1 handler for
 -- the left button.
--- If the handler returns true, it'll prevent any further processing of the
--- event.
+-- If any applicable button handler returns true, it'll propagate the click to other handlers.
 
 -- draw button and queue up event handlers
 function button(State, name, params)
@@ -15,14 +14,14 @@ function button(State, name, params)
 end
 
 -- process button event handlers
-function propagate_to_button_handlers(State, x, y, mouse_button)
+function mouse_press_consumed_by_any_button_handler(State, x, y, mouse_button)
   if State.button_handlers == nil then
     return
   end
   for _,ev in ipairs(State.button_handlers) do
     if x>ev.x and x<ev.x+ev.w and y>ev.y and y<ev.y+ev.h then
       if ev.onpress1 and mouse_button == 1 then
-        return ev.onpress1()
+        return not ev.onpress1()
       end
     end
   end