paramus

Generic UI

Jul 8th, 2026 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.05 KB | Gaming | 0 0
  1. local Gui = {
  2.     version="0.0.3",
  3.     buttons={}
  4. }
  5.  
  6. function Gui.newButton(name, x, y, width, height, text)
  7.     local button = {
  8.         name=name,
  9.         x=x,
  10.         y=y,
  11.         width=width,
  12.         height=height,
  13.         text=text,
  14.         color=colors.white,
  15.         textColor=colors.black,
  16.         clickColor=colors.gray,
  17.         baseColor=colors.white
  18.     }
  19.    
  20.     table.insert(Gui.buttons, button)
  21. end
  22.  
  23. function Gui.drawButtons()
  24.     for i,button in ipairs(Gui.buttons) do
  25.         paintutils.drawFilledBox(button.x, button.y, button.x+button.width-1, button.y+button.height-1, button.color)
  26.         term.setTextColor(button.textColor)
  27.         term.setCursorPos(button.x, math.ceil((button.height/2) + button.y - 1))
  28.         term.write(button.text)
  29.     end
  30. end
  31.  
  32. function Gui.buttonPressed(x,y)
  33.     for i,button in ipairs(Gui.buttons) do
  34.         if ((x >= button.x and x <= button.x+button.width-1) and (y >= button.y and y <= button.y+button.height-1)) then
  35.             return button
  36.         end
  37.     end
  38.    
  39.     return null
  40. end
  41.  
  42. return Gui
Advertisement
Add Comment
Please, Sign In to add comment