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:46:04 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-08-23 11:48:52 -0700
commit8747415461a921dd26cc2610471ddb411db0ed16 (patch)
treec103d3b63eac557d760503c62cda38c808291003 /button.lua
parent468b791050d9aa631871002e4fde70c3ea82bc0c (diff)
downloadlines.love-8747415461a921dd26cc2610471ddb411db0ed16.tar.gz
allow buttons to nest as well
Diffstat (limited to 'button.lua')
-rw-r--r--button.lua13
1 files changed, 11 insertions, 2 deletions
diff --git a/button.lua b/button.lua
index 748f5ae..c027b5c 100644
--- a/button.lua
+++ b/button.lua
@@ -1,6 +1,11 @@
 -- Simple immediate-mode buttons with (currently) just an onpress1 handler for
 -- the left button.
--- If any applicable button handler returns true, it'll propagate the click to other handlers.
+--
+-- Buttons can nest in principle, though I haven't actually used that yet.
+--
+-- Don't rely on the order in which handlers are run. Within any widget, all
+-- applicable button handlers will run. If _any_ of them returns true, the
+-- event will continue to propagate elsewhere in the widget.
 
 -- draw button and queue up event handlers
 function button(State, name, params)
@@ -18,11 +23,15 @@ function mouse_press_consumed_by_any_button_handler(State, x, y, mouse_button)
   if State.button_handlers == nil then
     return
   end
+  local result = false
   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 not ev.onpress1()
+        if not ev.onpress1() then
+          result = true
+        end
       end
     end
   end
+  return result
 end