MattiasBuelens

CCGUI demo

Jul 5th, 2012
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.20 KB | None | 0 0
  1. --[[
  2.  
  3.     ComputerCraft GUI
  4.     Demonstration program
  5.  
  6. --]]
  7.  
  8. -- Load dependencies
  9. dofile("/common/all")
  10. program.load("all")
  11.  
  12. local paint = true
  13. local isRunning = true
  14.  
  15. local screen = ccgui.Page:new{
  16.     horizontal = false,
  17.     background = colours.white,
  18.     _name = "screen"
  19. }
  20. local header = ccgui.FlowContainer:new{
  21.     horizontal = true,
  22.     _name = "header"
  23. }
  24. local headerTitle = ccgui.TextElement:new{
  25.     text = "CCGUI DEMONSTRATION",
  26.     align = ccgui.Align.Center,
  27.     stretch = true,
  28.     foreground = colours.white,
  29.     background = colours.blue,
  30.     _name = "headerTitle"
  31. }
  32. local btnQuit = ccgui.Button:new{
  33.     text = "X",
  34.     align = ccgui.Align.Right,
  35.     padding = ccgui.newMargins(0),
  36.     _name = "btnQuit"
  37. }
  38. btnQuit:on("buttonpress", function()
  39.     isRunning = false
  40. end)
  41. header:add(headerTitle, btnQuit)
  42.  
  43. local footer = ccgui.TextElement:new{
  44.     text = "Ready",
  45.     foreground = colours.white,
  46.     background = colours.lightGrey,
  47.     _name = "footer"
  48. }
  49.  
  50. local toolbar = ccgui.FlowContainer:new{
  51.     horizontal = true,
  52.     padding = ccgui.newMargins(0, 1),
  53.     spacing = 1,
  54.     _name = "toolbar"
  55. }
  56. local btnOne = ccgui.Button:new{
  57.     text = "One",
  58.     _name = "btnOne"
  59. }
  60. btnOne:on("buttonpress", function()
  61.     footer:setText("One pressed")
  62. end)
  63. local btnTwo = ccgui.Button:new{
  64.     text = "Two",
  65.     _name = "btnTwo"
  66. }
  67. btnTwo:on("buttonpress", function()
  68.     footer:setText("Two pressed")
  69. end)
  70. local btnThree = ccgui.Button:new{
  71.     text = "Three",
  72.     _name = "btnThree"
  73. }
  74. btnThree:on("buttonpress", function()
  75.     footer:setText("Three pressed")
  76. end)
  77. toolbar:add(btnOne, btnTwo, btnThree)
  78.  
  79. local fieldAddress = ccgui.FlowContainer:new{
  80.     horizontal = true,
  81.     padding = ccgui.newMargins(1),
  82.     _name = "fieldAddress"
  83. }
  84. local labelAddress = ccgui.TextElement:new{
  85.     text = "To: ",
  86.     _name = "labelAddress"
  87. }
  88. local textAddress = ccgui.TextInput:new{
  89.     _name = "textAddress"
  90. }
  91. textAddress:setText("mattias@island")
  92. fieldAddress:add(labelAddress, textAddress)
  93.  
  94. local textMessage = ccgui.TextArea:new{
  95.     stretch = true
  96. }
  97. screen:add(header, toolbar, fieldAddress, textMessage, footer)
  98.  
  99. screen:repaint()
  100. while isRunning do
  101.     local event, p1, p2, p3, p4, p5 = os.pullEvent()
  102.     screen:trigger(event, p1, p2, p3, p4, p5)
  103. end
  104.  
  105. -- Restore
  106. screen:reset()
Advertisement
Add Comment
Please, Sign In to add comment