1 -- Simple immediate-mode buttons with (currently) just an onpress1 handler for
4 -- Buttons can nest in principle, though I haven't actually used that yet.
6 -- Don't rely on the order in which handlers are run. Within any widget, all
7 -- applicable button handlers will run. If _any_ of them returns true, the
8 -- event will continue to propagate elsewhere in the widget.
10 -- draw button and queue up event handlers
11 function button(State
, name
, params
)
13 love
.graphics
.setColor(params
.bg
.r
, params
.bg
.g
, params
.bg
.b
, params
.bg
.a
)
14 love
.graphics
.rectangle('fill', params
.x
,params
.y
, params
.w
,params
.h
, 5,5)
16 if params
.icon
then params
.icon(params
) end
17 table.insert(State
.button_handlers
, params
)
20 -- process button event handlers
21 function mouse_press_consumed_by_any_button(State
, x
, y
, mouse_button
)
22 local button_pressed
= false
23 local consume_press
= true
24 for _
,ev
in ipairs(State
.button_handlers
) do
25 if x
>ev
.x
and x
<ev
.x
+ev
.w
and y
>ev
.y
and y
<ev
.y
+ev
.h
then
26 if ev
.onpress1
and mouse_button
== 1 then
34 return button_pressed
and consume_press