Advertisement
nik1111

group

May 19th, 2022
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. --
  2. -- Created by Grcpils
  3. -- 03/14/2021
  4. -- Github: https://github.com/grcpils/cc-gui_api
  5. -- Please do not delete this header ;)
  6. --
  7.  
  8. local Utils = require("GUI/utils")
  9.  
  10. local drawLabel = function (grp)
  11. local Y = grp.ymin
  12. local X = math.floor((grp.xmax + grp.xmin - string.len(grp.label)) / 2)
  13. GUI_MONITOR.setBackgroundColor(colors.black)
  14. GUI_MONITOR.setCursorPos(X, Y)
  15. GUI_MONITOR.write(" " .. grp.label .. " ")
  16. end
  17.  
  18. local draw = function (grp)
  19. GUI_MONITOR.setBackgroundColor(grp.color)
  20. Utils.drawShapeOut(grp)
  21. GUI_MONITOR.setBackgroundColor(colors.black)
  22. end
  23.  
  24. local drawAll = function ()
  25. table.foreach(GUI_GROUPS, function (key, grp)
  26. Utils.printInfo("[GUI] Draw group '%s' (id:%s)\n", grp.label, key)
  27. draw(grp)
  28. drawLabel(grp)
  29. end)
  30. end
  31.  
  32. local refresh = function ()
  33. table.foreach(GUI_GROUPS, function (key, grp)
  34. draw(grp)
  35. drawLabel(grp)
  36. end)
  37. end
  38.  
  39. local label = function(id, label)
  40. table.foreach(GUI_GROUPS, function (key, grp)
  41. if id == key then
  42. grp.label = label
  43. end
  44. drawLabel(grp)
  45. end)
  46. end
  47.  
  48. local new = function(label, pos, size, color)
  49. local xmin, xmax, ymin, ymax = Utils.getCoordonate(pos, size)
  50. local Group = {
  51. label = label,
  52. xmin = xmin,
  53. xmax = xmax,
  54. ymin = ymin,
  55. ymax = ymax,
  56. color = color
  57. }
  58.  
  59. local setLabel = function (label)
  60. Group.label = label
  61. refresh()
  62. end
  63.  
  64. table.insert(GUI_GROUPS, Group)
  65. return {
  66. setLabel = setLabel
  67. }
  68. end
  69.  
  70. return {
  71. new = new,
  72. label = label,
  73. drawAll = drawAll
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement