Advertisement
svemat01

Untitled

Oct 25th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. if viewportAPI then os.unloadAPI("viewportAPI") end
  2. os.loadAPI("viewportAPI")
  3. if buttonAPI then os.unloadAPI("buttonAPI") end
  4. os.loadAPI("buttonAPI")
  5. if eventDispatcherAPI then os.unloadAPI("eventDispatcherAPI") end
  6. os.loadAPI("eventDispatcherAPI")
  7.  
  8. viewport = viewportAPI.new({term = peripheral.wrap("back")})
  9.  
  10. button = buttonAPI.new({
  11. text = "test",
  12. x = 5,
  13. y = 5,
  14. height = 1,
  15. width = 6,
  16. isSticky = false,
  17. backgroundColor = colors.green
  18. })
  19.  
  20. viewport:addElement(button)
  21. viewport:redraw()
  22.  
  23. function clickHandler(element, posX, posY)
  24. element.backgroundColor = element.backgroundColor == colors.red and colors.green or colors.red
  25. return true
  26. end
  27.  
  28. button.callback = clickHandler
  29.  
  30. while true do
  31. event, side, xPos, yPos = os.pullEvent("monitor_touch")
  32. viewport:handleClick(xPos, yPos)
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement