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
)
12 if State
.button_handlers
== nil then
13 State
.button_handlers
= {}
15 love
.graphics
.setColor(params
.color
[1], params
.color
[2], params
.color
[3])
16 love
.graphics
.rectangle('fill', params
.x
,params
.y
, params
.w
,params
.h
, 5,5)
17 if params
.icon
then params
.icon(params
) end
18 table.insert(State
.button_handlers
, params
)
21 -- process button event handlers
22 function mouse_press_consumed_by_any_button_handler(State
, x
, y
, mouse_button
)
23 if State
.button_handlers
== nil then
26 local button_pressed
= false
27 local consume_press
= true
28 for _
,ev
in ipairs(State
.button_handlers
) do
29 if x
>ev
.x
and x
<ev
.x
+ev
.w
and y
>ev
.y
and y
<ev
.y
+ev
.h
then
30 if ev
.onpress1
and mouse_button
== 1 then
38 return button_pressed
and consume_press