· 4 years ago · Aug 13, 2021, 10:34 PM
1-- Graphics API made by Benjaneb --
2
3local width, height = term.getSize()
4
5function button(text, fg, bg, x, y, func)
6 term.setCursorPos(x, y)
7 term.blit(text, fg, bg)
8 local event, button, clickX, clickY = os.pullEvent("mouse_click")
9 if button == 0 and clickX > x and clickX < (x + #text) and clickY > y and clickY < (y + 1) then
10 func()
11 end
12end
13
14function menu(menu)
15 for key, value in pairs(menu) do
16 button(value.text, colors.black, colors.white,
17 (width / 2) - (#value.text / 2), (height / 2) - math.ceil(#menu / 2), value.func)
18 end
19end