Advertisement
derkoch

example

Oct 14th, 2013
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.70 KB | None | 0 0
  1. -- load ALL the APIs!
  2. os.loadAPI("RBB/helper")
  3. os.loadAPI("RBB/guiElements")
  4. os.loadAPI("RBB/screen")
  5.  
  6. -- Function for the Buttons, just prints the parameter
  7. function fancyFunction(p1, p2)
  8.     print(tostring(p1) .. " , " .. tostring(p2))
  9. end
  10.  
  11. -- Function for Picker, just prints the parameter
  12. function incdecFunction(param)
  13.     print("incdec: " .. tostring(param))
  14. end
  15.  
  16. -- Create a new Screen. The Monitor is on the "right" and will have a 4 by 4 grid
  17. local rows = 4
  18. local cols = 4
  19. local thisScreen = screen.Screen.create("right", rows, cols)
  20.  
  21. -- Lets make some buttons
  22. -- For more detailed info, look into the documentation ;)
  23. local btn = guiElements.Button.create("1", "Button", false, fancyFunction, {"Button", "derp"})
  24. local btn2 = guiElements.Button.create("2", "Button2", true, fancyFunction, {"Button2", "derp"})
  25. local btn3 = guiElements.Button.create("3", "Button3", false, fancyFunction, {"Button3", "derp"})
  26. local btn4 = guiElements.Button.create("4", "Button4", false, fancyFunction, {"Button4", "derp"})
  27. -- Lets make some RadioButtons:
  28. -- The radioIndex can be a string or a number, it's just there to group the buttons
  29. btn3:setRadioIndex("herpderp")
  30. btn4:setRadioIndex("herpderp")
  31.  
  32. -- And now a label
  33. local lbl = guiElements.Label.create("123","Down here!",{h = "center", v = "center"})
  34. -- and when where at it, lets turn the background of the label blue!
  35. lbl:setBGColor(colors.blue)
  36. lbl:setTextPosition({h = "right", v = "bottom"})
  37.  
  38. -- Now we create a "Picker". This one's a bit complicated
  39. -- First two parameters are like button and label, but the 3rd is the starting index for the table in the 4th parameter
  40. -- The index is 2 so we start with "def"
  41. local picker = guiElements.Picker.create("picky", "Picker1", 2, {"abc", "def", "ghi", "jkl"})
  42. -- Set the function that is called when the "-" is clicked
  43. picker:setDecFunction(incdecFunction)
  44. -- Set the function that is called when the "+" is clicked
  45. picker:setIncFunction(incdecFunction)
  46.  
  47.  
  48. -- Add ALL the elements to the grid
  49. thisScreen:addElementToGrid(picker,2,3)
  50. -- This ones is different! the buttons will have a 2x2 size
  51. thisScreen:addElementToGrid(btn,{1,2},{1,2})
  52. thisScreen:addElementToGrid(btn2,1,3)
  53. thisScreen:addElementToGrid(btn3,3,2)
  54. thisScreen:addElementToGrid(btn4,4,1)
  55. thisScreen:addElementToGrid(lbl,4,{2,3,4})
  56.  
  57. -- This has to be called after adding all the elements, it just sets up each element...the automatic stuff ;)
  58. thisScreen:initGrid()
  59. -- Initially draws everything, only needs to be called once
  60. thisScreen:draw()
  61.  
  62.  
  63. -- Basic loop to get the touch events from the monitor and check them on the screen
  64. while true do
  65.     event,side,x,y = os.pullEvent("monitor_touch")
  66.     thisScreen:checkTouchEvent(event,side,x,y)
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement