diff options
-rw-r--r-- | button.lua | 13 |
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 |