Advertisement
Mobble

test button api

Apr 25th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. os.loadAPI("button")
  2.  
  3. -- Create 4 Buttons, 3 Testing and 1 Exit
  4. local testButton = button.new(2, 2, 20, 2, "Hello World!")
  5. local testButton2 = button.new(2, 6, 20 , 2, "Sup World!")
  6. local testButton3 = button.new(2, 10, 20, 2, "Nice World!")
  7. local exit = button.new(2, 14, 8, 2, "Exit")
  8.  
  9. --Simple Loop Value
  10. local alive = true
  11.  
  12. -- Create a Test ButtonGroup
  13. local testGroup = button.newButtonGroup()
  14.  
  15. -- Simply Applies a different label to a button, adds "!"
  16. function textChange(btn)
  17. btn:setText(btn:getText().."!")
  18. end
  19.  
  20. -- Adds 2 Toggleable Buttons to the ButtonGroup,
  21. -- the buttons MUST be toggleable. This acts like
  22. -- radio buttons, only one button in a button group
  23. -- is active at a time.
  24. testGroup:addButtons(testButton2, testButton3)
  25.  
  26. -- setToFlash make the button non-toggleable. It flashes instead of
  27. -- activating or de-activating and fires it's actions ONCE.
  28. -- Adds TextChange Action to Button, add's a "!" to end of label on click.
  29. testButton:setToFlash()
  30. testButton:addAction(textChange)
  31. exit:setToFlash()
  32. exit:addAction(function() alive = false; end) -- Kill Loop on Click
  33.  
  34. -- Use button API Methods for utility.
  35. -- Clear Screen and Initial Update to draw buttons
  36. term.clear()
  37. button.update()
  38.  
  39. while alive do
  40. event, b, x, y = os.pullEvent("mouse_click")
  41. button.update(x, y) -- Pass Input X,Y to Update, Any buttons there are activated
  42. sleep(0.05)
  43. end
  44.  
  45. term.clear()
  46. term.setCursorPos(1, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement