Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ HorizonUI
- Design or GUI api
- Made by RodrickLord ]]
- local termX,termY = term.getSize()
- local centerX,centerY = termX/2+1,termY/2
- -- Simple Functions
- function centerWrite(text,y,tColor)
- if tColor then term.setTextColor(tColor) end
- local _,cy = term.getCursorPos()
- term.setCursorPos(centerX-#text/2,y or cy)
- write(text)
- end
- function clearLine(y,bColor)
- local _,cy = term.getCursorPos()
- if bColor then term.setBackgroundColor(bColor) end
- term.setCursorPos(1,y or cy)
- term.clearLine()
- end
- function clear(bColor)
- if bColor then term.setBackgroundColor(bColor) end
- term.clear()
- end
- -- Buttons
- buttons = {
- _default = {tColor = colors.white, bColor = colors.lightBlue, enabled = true}
- }
- function createButton(id,text,x,y,x2,y2,action,tColor,bColor,enabled)
- if not buttons[id] then
- local default = buttons._default
- buttons[id] = default
- buttons[id] = {
- text = text, x = x, y = y, x2 = x2 or x+#text+1, y2 = y2 or y+2, tColor = tColor or colors.white, bColor = bColor or colors.lightBlue, enabled = enabled or true
- }
- if enabled then drawButton(id) end
- return true
- else
- return false
- end
- end
- function deleteButton(id)
- if buttons[id] then
- buttons[id] = nil
- return true
- else
- return false
- end
- end
- function drawButton(id)
- if buttons[id] then
- paintutils.drawFilledBox(buttons[id].x,buttons[id].y,buttons[id].x2,buttons[id].y2,buttons[id].bColor)
- term.setCursorPos(buttons[id].x+1,buttons[id].y+1)
- term.setTextColor(buttons[id].tColor)
- write(buttons[id].text)
- else
- return false
- end
- end
- function enableButton(...)
- local args = {...}
- for _,v in pairs(args) do
- if button[v] then button[v].enabled = true end
- end
- end
- function disableButton(...)
- local args = {...}
- for _,v in pairs(args) do
- if button[v] then button[v].enabled = false end
- end
- end
- function setButtonOption(id,key,value)
- if buttons[id][key] then
- buttons[id][key] = value
- else
- return false
- end
- end
- function handleClick()
- buttons._running = true
- while buttons._running do
- local _,_,cx,cy = os.pullEvent("mouse_click")
- for k,v in pairs(buttons) do
- if v.x and v.y and v.x2 and v.y2 then
- if (cx>=v.x and cx<=v.x2) and (cy>=v.y and cy<=v.y2) then v.action() end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement