allow buttons to nest as well
This commit is contained in:
parent
468b791050
commit
8747415461
13
button.lua
13
button.lua
|
@ -1,6 +1,11 @@
|
||||||
-- Simple immediate-mode buttons with (currently) just an onpress1 handler for
|
-- Simple immediate-mode buttons with (currently) just an onpress1 handler for
|
||||||
-- the left button.
|
-- 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
|
-- draw button and queue up event handlers
|
||||||
function button(State, name, params)
|
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
|
if State.button_handlers == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
local result = false
|
||||||
for _,ev in ipairs(State.button_handlers) do
|
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 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
|
if ev.onpress1 and mouse_button == 1 then
|
||||||
return not ev.onpress1()
|
if not ev.onpress1() then
|
||||||
|
result = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue