MiStAWaFFlEZZ

example

Apr 21st, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. --require the curlib library.
  2. --the name 'curlib' stands for _CURS0R_'s library
  3. --but has also some libname inpiration on 'curses' or 'pcurses'
  4. --just the name, because comparing 'curses' or 'pcurses' with this
  5. --is like comparing a continent with a rock.
  6. local curlib = require("curlib");
  7. local align = require("textalign");
  8.  
  9. --make some other default requirments...
  10. local component = require("component");
  11. local term = require("term");
  12. local gpu = component.gpu;
  13.  
  14. local running = true;
  15.  
  16. --create a new app
  17. local app = curlib.app:new();
  18.  
  19. --create a new window
  20. local win1 = curlib.window:new({ x = 3, y = 2,
  21. width = 60, height = 20, shadow = true});
  22.  
  23. --create a new button
  24. local button = curlib.button:new({
  25. x = win1.width - 9,
  26. y = win1.height -1,
  27. width = 8, height = 1,
  28. text = "Quit", shadow = true}
  29. );
  30.  
  31. --create a onClick event handler
  32. button.onClick = function(control, x, y)
  33. app.status("my click function called");
  34. running = false;
  35. end
  36.  
  37. --create a new text or label or whatevery text thing
  38. local txt1 = curlib.text:new({ x = 2, y = 2, width = 15,
  39. text = "all your base are bellong to us...", align = align.direction.topLeft });
  40.  
  41. local txt2 = curlib.text:new({ x = 20, y = 2, width = 15,
  42. text = "all your base are bellong to us...", align = align.direction.topCenter });
  43.  
  44. local txt3 = curlib.text:new({ x = 38, y = 2, width = 15,
  45. text = "all your base are bellong to us...", align = align.direction.topRight });
  46.  
  47. local btnAlign1 = curlib.button:new({ x = 2, y = 8, width = 10, height = 5, text = "align labels left"});
  48. local btnAlign2 = curlib.button:new({ x = 20, y = 8, width = 10, height = 5, text = "align labels center"});
  49. local btnAlign3 = curlib.button:new({ x = 38, y = 8, width = 10, height = 5, text = "align labels right"});
  50.  
  51. btnAlign1.onClick = function (control, x, y)
  52. txt1.align = align.direction.topLeft;
  53. txt2.align = align.direction.topLeft;
  54. txt3.align = align.direction.topLeft;
  55. txt1.dirty = true;
  56. txt2.dirty = true;
  57. txt3.dirty = true;
  58. end
  59.  
  60. btnAlign2.onClick = function (control, x, y)
  61. txt1.align = align.direction.topCenter;
  62. txt2.align = align.direction.topCenter;
  63. txt3.align = align.direction.topCenter;
  64. txt1.dirty = true;
  65. txt2.dirty = true;
  66. txt3.dirty = true;
  67. end
  68.  
  69. btnAlign3.onClick = function (control, x, y)
  70. txt1.align = align.direction.topRight;
  71. txt2.align = align.direction.topRight;
  72. txt3.align = align.direction.topRight;
  73. txt1.dirty = true;
  74. txt2.dirty = true;
  75. txt3.dirty = true;
  76. end
  77.  
  78. --create a new input box
  79. local input1 = curlib.input:new({x = 2, y = 15, width = 30,
  80. text="some text in inputbox nº1"});
  81.  
  82. --and another one :)
  83. local input2 = curlib.input:new({x = 2, y = 17, width = 30});
  84.  
  85. --adds the button to the window
  86. win1:addChild(button);
  87. --adds the text to the window
  88. win1:addChild(txt1);
  89. win1:addChild(txt2);
  90. win1:addChild(txt3);
  91. win1:addChild(btnAlign1);
  92. win1:addChild(btnAlign2);
  93. win1:addChild(btnAlign3);
  94.  
  95. --adds the input box1 to the window
  96. win1:addChild(input1);
  97. --adds the input box2 to the window
  98. win1:addChild(input2);
  99.  
  100. --adds the window to the app
  101. app:addChild(win1);
  102.  
  103. --initializes the app and makes a first screen draw of everything
  104. app:init();
  105.  
  106.  
  107. -- application main loop
  108. while running do
  109.  
  110. -- makes the app treat events, every event not handled is returned
  111. -- to be handled by the user.
  112. local event, addr, arg1, arg2, arg3 = app:doEvents();
  113.  
  114. --in this case we are handling the 'interrupted' event
  115. --so we can quit the app in Ctrl+C
  116. if (event == "interrupted") then
  117. running = false;
  118. end
  119. end
  120.  
  121. -- clean the pallete (need for tier2 screens)
  122. curlib.cleanPalette();
  123.  
  124. -- do a lame screen restore... you can do it in a better way ^^
  125. gpu.setBackground(0);
  126. gpu.setForeground(0xc1c1c1);
  127. term.clear();
  128.  
  129. --end
Advertisement
Add Comment
Please, Sign In to add comment