text.love/button.lua

21 lines
663 B
Lua
Raw Normal View History

2022-05-18 06:18:56 +00:00
-- simple immediate-mode buttons
2022-05-18 06:24:46 +00:00
Button_handlers = {}
-- draw button and queue up event handlers
function button(name, params)
love.graphics.setColor(params.color[1], params.color[2], params.color[3])
love.graphics.rectangle('fill', params.x,params.y, params.w,params.h, 5,5)
if params.icon then params.icon(params.x, params.y) end
2022-05-18 06:24:46 +00:00
table.insert(Button_handlers, params)
end
-- process button event handlers
2022-05-18 06:18:56 +00:00
function propagate_to_button_handlers(x, y, mouse_button)
2022-05-18 06:24:46 +00:00
for _,ev in ipairs(Button_handlers) do
if x>ev.x and x<ev.x+ev.w and y>ev.y and y<ev.y+ev.h then
2022-05-18 06:18:56 +00:00
if ev.onpress1 and mouse_button == 1 then ev.onpress1() end
end
end
end