R3C0NF16UR3D

guiElements.lua

Jul 31st, 2023
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.29 KB | None | 0 0
  1. --FIXME: Frames need a new draw function. problems with dimensions
  2. --FIXME:
  3.  
  4.  
  5.  
  6. local component = require("component")
  7. local gpu = component.gpu
  8. local event = require("event")
  9. local unicode = require("unicode")
  10. local filesystem = require("filesystem")
  11. local wm = require("windowmanager/libs/wm")
  12.  
  13. local term = require("term")
  14. local shell = require("shell")
  15. local text = require("text")
  16. local sh = require("sh")
  17.  
  18.  
  19. local guiElements = {}
  20.  
  21. local lastElement = {
  22. ["id"] = "none",
  23. ["text"] = "no text",
  24. ["x"] = 0,
  25. ["y"] = 0,
  26. ["w"] = 0,
  27. ["h"] = 0,
  28. }
  29. -- frames
  30. local Frame = {
  31. -- horizontal, vertical, left-top, right-top, left-bottom, right-bottom
  32. ["Double"] = {0x2550, 0x2551, 0x2554, 0x2557, 0x255A, 0x255D},
  33. ["Small"] = {0x2500, 0x2502, 0x250C, 0x2510, 0x2514, 0x2518},
  34. ["Bold"] = {0x2501, 0x2503, 0x0250F, 0x2513, 0x2517, 0x251B}
  35. }
  36.  
  37.  
  38. local color={}
  39. color.black=0x000000
  40. color.gray=0xA9A9A9
  41. color.lightBlue=0x808080
  42. color.white=0xFFFFFF
  43. color.magenta=0xFF00FF
  44. color.yellow=0xFFFF00
  45. color.green=0x00FF00
  46. color.darkGreen=0x008000
  47. color.blue=0x0000ff
  48. color.red=0xFF0000
  49. color.orange=0xFFA500
  50. color.brown=0xA52A2A
  51. color.lightRed=0xF00000
  52. color.darkGray=0x202020
  53.  
  54. -- element colors
  55. local Color = {}
  56. Color.LabelBackground = color.gray
  57. Color.LabelForeground = color.black
  58. Color.ButtonBackground = color.blue
  59. Color.ButtonForeground = color.white
  60. Color.ButtonActiveBackground = color.green
  61. Color.ButtonActiveForeground = color.white
  62. Color.LineBackground = color.gray
  63. Color.LineForeground = color.black
  64. Color.FrameBackground = color.gray
  65. Color.FrameForeground = color.black
  66. Color.HSliderBackground = color.black
  67. Color.HSliderForeground = color.white
  68. Color.HSliderActiveBackground = color.black
  69. Color.HSliderActiveForeground = color.green
  70. Color.VSliderBackground = color.black
  71. Color.VSliderForeground = color.white
  72. Color.VSliderActiveBackground = color.black
  73. Color.VSliderActiveForeground = color.green
  74. Color.HBarBackground = color.black
  75. Color.HBarForeground = color.green
  76. Color.CheckboxBackground = color.gray
  77. Color.CheckboxForeground = color.black
  78. Color.InputBackground = color.black
  79. Color.InputForeground = color.white
  80. Color.InputActiveBackground = color.blue
  81. Color.InputActiveForeground = color.white
  82. Color.ListBackground = color.blue
  83. Color.ListForeground = color.white
  84. Color.ListActiveBackground = color.green
  85. Color.ListActiveForeground = color.white
  86. Color.RadioBackground = color.gray
  87. Color.RadioForeground = color.black
  88. Color.DrawBufferBackground = color.gray
  89. Color.DrawBufferForeground = color.black
  90. Color.TerminalBackground = color.black
  91. Color.TerminalForeground = color.white
  92.  
  93. -- local functions
  94. local function getPosAlign(win, self)
  95. if self.alignment == "left" then
  96. return win.x + self.x
  97. elseif self.alignment == "center" then
  98. return win.x + self.x + math.floor(self.w/2) - math.floor(string.len(string.sub(self.text, 1, self.w))/2)
  99. elseif self.alignment == "right" then
  100. return win.x + self.x + self.w - string.len(string.sub(self.text, 1, self.w))
  101. end
  102. end
  103.  
  104. local function splitWords(Lines, limit)
  105. while #Lines[#Lines] > limit do
  106. Lines[#Lines+1] = Lines[#Lines]:sub(limit+1)
  107. Lines[#Lines-1] = Lines[#Lines-1]:sub(1,limit)
  108. end
  109. end
  110. local function wrap(str, limit)
  111. local Lines, here, limit, found = {}, 1, limit or 72, str:find("(%s+)()(%S+)()")
  112. if found then
  113. Lines[1] = string.sub(str,1,found-1) -- Put the first word of the string in the first index of the table.
  114. else Lines[1] = str end
  115. str:gsub("(%s+)()(%S+)()",
  116. function(sp, st, word, fi) -- Function gets called once for every space found.
  117. splitWords(Lines, limit)
  118.  
  119. if fi-here > limit then
  120. here = st
  121. Lines[#Lines+1] = word -- If at the end of a line, start a new table index...
  122. else Lines[#Lines] = Lines[#Lines].." "..word end -- ... otherwise add to the current table index.
  123. end)
  124. splitWords(Lines, limit)
  125.  
  126. return Lines
  127. end
  128.  
  129. function correctPos(win, self)
  130. local x = self.x + win.x
  131. local y = self.y + win.y
  132. local w = self.w
  133. local h = self.h
  134.  
  135. while x + w > win.x + win.w - 1 do -- element is too long
  136. w = w - 1
  137. end
  138. if w < 0 then
  139. w = 0
  140. end
  141. while y + h > win.y + win.h do -- element is too long
  142. h = h - 1
  143. end
  144. if h < 0 then
  145. h = 0
  146. end
  147. return x, y, w, h
  148. end
  149.  
  150. function updateLastElement(self)
  151. lastElement.id = self.id
  152. lastElement.text = self.text
  153. lastElement.x =self.x
  154. lastElement.y =self.y
  155. lastElement.w =self.w
  156. lastElement.h =self.h
  157. end
  158.  
  159. local history = {}
  160.  
  161. local terminalTimer = nil
  162. shell.prime()
  163.  
  164. function terminalCallback(win, self)
  165. if terminalTimer then
  166. event.cancel(terminalTimer)
  167. end
  168. local foreground = gpu.setForeground(0xFF0000)
  169. term.write(sh.expand(os.getenv("PS1") or "$ "))
  170. gpu.setForeground(foreground)
  171. term.setCursorBlink(true)
  172. local ok, command
  173. ok, command = pcall(term.read, history, nil, sh.hintHandler)
  174. if not command then
  175. io.write("exit\n") -- pipe closed
  176. wm.closeWindow(win)
  177. end
  178.  
  179. command = text.trim(command)
  180.  
  181. if command == "exit" then
  182. wm.closeWindow(win)
  183. elseif command ~= "" then
  184. local result, reason
  185. result, reason = sh.execute(_ENV, command)
  186. if term.getCursor() > 1 then
  187. print()
  188. end
  189. if not result then
  190. io.stderr:write((reason and tostring(reason) or "unknown error") .. "\n")
  191. end
  192. end
  193. if ok == true then
  194. if wm.getActiveWindow() == win then
  195. terminalTimer = event.timer(0, function()terminalCallback(win,self) end)
  196. end
  197. end
  198. end
  199.  
  200. function drawTerminal(win, self)
  201. local x, y, w, h = correctPos(win, self)
  202. gpu.setBackground(Color.TerminalBackground)
  203. gpu.setForeground(Color.TerminalForeground)
  204. gpu.fill(x, y, w, h, " ")
  205.  
  206. local x, y, w, h = correctPos(win, self)
  207.  
  208. term.setViewport(w, h, x - 1, y - 1, 1, 1)
  209.  
  210. if self.firstCall == true then
  211. if not term.isAvailable() then event.pull("term_available") end
  212. loadfile(shell.resolve("source","lua"))("/etc/profile")
  213. if not term.isAvailable() then -- don't clear unless we lost the term
  214. while not term.isAvailable() do
  215. event.pull("term_available")
  216. end
  217. term.clear()
  218. end
  219. self.firstCall = false
  220. local gpu = term.gpu()
  221. if wm.getActiveWindow() == win then
  222. terminalCallback(win, self)
  223. -- terminalTimer = event.timer(0, terminalCallback)
  224. end
  225. end
  226. end
  227.  
  228. -- draw callbacks
  229. function drawBuffer(win, self)
  230. local x, y, w, h = correctPos(win, self)
  231. local xv = self.userData1.xv
  232. local yv = self.userData1.yv
  233. local oldXV = self.userData2.oldXV
  234. local oldYV = self.userData2.oldYV
  235. if oldXV < xv then
  236. gpu.copy(x + 1, y, self.w - 1, self.h, - 1, 0)
  237. oldBG = - 1
  238. oldFG = - 1
  239. for i = 1, self.h do
  240. bg = self.data[xv + self.w][i + yv].bg
  241. if bg ~= oldBG then
  242. gpu.setBackground(bg)
  243. oldBG = bg
  244. end
  245. fg = self.data[xv + self.w][i + yv].fg
  246. if fg ~= oldFG then
  247. gpu.setForeground(fg)
  248. oldFG = fg
  249. end
  250. gpu.set(x + self.w - 1, y + i - 1, self.data[xv + self.w][i + yv].character)
  251. end
  252. self.userData2.oldXV = xv
  253. elseif oldYV < yv then
  254. gpu.copy(x, y + 1, self.w, self.h - 1, 0, - 1)
  255. oldBG = - 1
  256. oldFG = - 1
  257. for i = 1, self.w do
  258. bg = self.data[xv + i][self.h + yv].bg
  259. if bg ~= oldBG then
  260. gpu.setBackground(bg)
  261. oldBG = bg
  262. end
  263. fg = self.data[xv + i][self.h + yv].fg
  264. if fg ~= oldFG then
  265. gpu.setForeground(fg)
  266. oldFG = fg
  267. end
  268. gpu.set(x + i - 1, y + self.h - 1, self.data[xv + i][self.h + yv].character)
  269. end
  270. self.userData2.oldYV = yv
  271. elseif oldXV > xv then
  272. oldBG = - 1
  273. oldFG = - 1
  274. gpu.copy(x, y, self.w - 1, self.h, 1, 0)
  275. for i = 1, self.h do
  276. bg = self.data[xv + 1][i + yv].bg
  277. if bg ~= oldBG then
  278. gpu.setBackground(bg)
  279. oldBG = bg
  280. end
  281. fg = self.data[xv + 1][i + yv].fg
  282. if fg ~= oldFG then
  283. gpu.setForeground(fg)
  284. oldFG = fg
  285. end
  286. gpu.set(x, y + i - 1, self.data[xv + 1][i + yv].character)
  287. end
  288. self.userData2.oldXV = xv
  289. elseif oldYV > yv then
  290. local oldBG = -1
  291. local oldFG = -1
  292. gpu.copy(x, y, self.w, self.h - 1, 0, 1)
  293. for i = 1, self.w do
  294. bg = self.data[xv + i][yv].bg
  295. if bg ~= oldBG then
  296. gpu.setBackground(bg)
  297. oldBG = bg
  298. end
  299. fg = self.data[xv + i][yv].fg
  300. if fg ~= oldFG then
  301. gpu.setForeground(fg)
  302. oldFG = fg
  303. end
  304. gpu.set(x + i - 1, y, self.data[xv + i][yv].character)
  305. end
  306. self.userData2.oldYV = yv
  307. else
  308. local oldBG = -1
  309. local oldFG = -1
  310. for i = 1, self.w do
  311. for j = 1, self.h do
  312. bg = self.data[i + xv][j + yv].bg
  313. if bg ~= oldBG then
  314. gpu.setBackground(bg)
  315. oldBG = bg
  316. end
  317. fg = self.data[i + xv][j + yv].fg
  318. if fg ~= oldFG then
  319. gpu.setForeground(fg)
  320. oldFG = fg
  321. end
  322. gpu.set(x + i - 1, y + j - 1, self.data[i + xv][j + yv].character)
  323. end
  324. end
  325. self.userData2.oldYV = yv
  326. self.userData2.oldXV = xv
  327. end
  328. end
  329.  
  330. function guiElements.setBufferViewport(self, x, y)
  331. self.userData2.oldXV = self.userData1.xv
  332. self.userData2.oldYV = self.userData1.yv
  333. self.userData1.xv = x
  334. self.userData1.yv = y
  335. end
  336.  
  337. function guiElements.bufferSetBackground(self, bg)
  338. self.background = bg
  339. end
  340.  
  341. function guiElements.bufferSetForeground(self, fg)
  342. self.foreground = fg
  343. end
  344.  
  345. function guiElements.bufferSet(self, x, y, c)
  346. self.data[x][y] = {["bg"] = self.background, ["fg"] = self.foreground, ["character"] = c}
  347. end
  348.  
  349. function guiElements.bufferFill(self, x, y, w, h, c)
  350. for i = x, x + w - 1 do
  351. for j = y, y + h - 1 do
  352. guiElements.bufferSet(self, i, j, c)
  353. end
  354. end
  355. end
  356.  
  357.  
  358.  
  359. function drawRadio(win, self)
  360. self.h = #self.data
  361. local x, y, w, h = correctPos(win, self)
  362.  
  363. for i = 1, #self.data do
  364. gpu.setBackground(self.background)
  365. gpu.setForeground(self.foreground)
  366. local text = ""
  367. if self.alignment == "left" then
  368. if i == self.selected then
  369. text = self.data[i] .. " (X)"
  370. else
  371. text = self.data[i] .. " ( )"
  372. end
  373. elseif self.alignment == "right" then
  374. if i == self.selected then
  375. text = "(X) " .. self.data[i]
  376. else
  377. text = "( ) " .. self.data[i]
  378. end
  379. end
  380. local sl = (x + string.len(text))
  381. if sl > x + w then
  382. sl = x + w - sl - 1
  383. end
  384. if y + i - 1 < win.y + win.h then
  385. if x <= win.x + win.w - 2 then
  386. gpu.fill(x, y + i - 1, w, 1, " ")
  387. gpu.set(x, y + i - 1, string.sub(text, 1, sl))
  388. end
  389. end
  390. end
  391. end
  392.  
  393.  
  394.  
  395. function drawList(win, self)
  396. local x, y, w, h = correctPos(win, self)
  397. gpu.setBackground(self.background)
  398. gpu.setForeground(self.foreground)
  399. gpu.fill(x, y, w, h, " ")
  400. for i = self.selected, #self.data do
  401. if i - self.selected <= h - 1 then
  402. if i == self.selected then
  403. gpu.setBackground(self.activeBackground)
  404. gpu.setForeground(self.activeForeground)
  405. else
  406. gpu.setBackground(self.background)
  407. gpu.setForeground(self.foreground)
  408. end
  409. gpu.fill(x, y + i - self.selected, w, 1, " ")
  410. if h >= 1 then
  411. text = self.data[i]
  412. local sl = (x + string.len(text))
  413. if sl > x + w then
  414. sl = x + w - sl - 1
  415. end
  416. if x <= win.x + win.w - 2 then
  417. gpu.set(x, y + i - self.selected, string.sub(text, 1, sl))
  418. end
  419. end
  420. end
  421. end
  422. end
  423.  
  424. function drawInput(win, self)
  425. local x, y, w, h = correctPos(win, self)
  426. if self.isActive == true then
  427. gpu.setBackground(self.activeBackground)
  428. gpu.setForeground(self.activeForeground)
  429. else
  430. gpu.setBackground(self.background)
  431. gpu.setForeground(self.foreground)
  432. end
  433. gpu.fill(x, y, w, h, " ")
  434. local tmpText = self.text
  435. if self.protected == true then
  436. tmpText = ""
  437. for i = 1, string.len(self.text) do
  438. tmpText = tmpText .. "*"
  439. end
  440. end
  441. if h >= 1 then
  442. local sl = (x + string.len(tmpText))
  443. if sl > x + w then
  444. sl = x + w - sl - 1
  445. end
  446. if x <= win.x + win.w - 2 then
  447. gpu.set(x, y, string.sub(tmpText, 1, sl))
  448. end
  449. end
  450. end
  451.  
  452. function drawCheckbox(win, self)
  453. local x, y, w, h = correctPos(win, self)
  454. gpu.setBackground(self.background)
  455. gpu.setForeground(self.foreground)
  456. gpu.fill(x, y, w, h, " ")
  457. local text = ""
  458. if self.alignment == "left" then
  459. if self.state == true then
  460. text = self.text .. " [X]"
  461. elseif self.state == false then
  462. text = self.text .. " [ ]"
  463. end
  464. elseif self.alignment == "right" then
  465. if self.state == true then
  466. text = "[X] " .. self.text
  467. elseif self.state == false then
  468. text = "[ ] " .. self.text
  469. end
  470. end
  471. if h >= 1 then
  472. local sl = (x + string.len(text))
  473. if sl > x + w then
  474. sl = x + w - sl - 1
  475. end
  476. if x <= win.x + win.w - 2 then
  477. gpu.set(x, y, string.sub(text, 1, sl))
  478. end
  479. end
  480. end
  481.  
  482. function drawVSlider(win, self)
  483. gpu.setBackground(self.background)
  484. gpu.setForeground(self.foreground)
  485. local x, y, w, h = correctPos(win, self)
  486. gpu.fill(x, y + 1, w, h - 1, " ")
  487. if y < win.y + win.h then
  488. if x < win.x + win.w - 1 then
  489. gpu.set(x, y, unicode.char(0x21E7))
  490. end
  491. end
  492. if y + self.h - 1 < win.y + win.h then
  493. if x < win.x + win.w - 1 then
  494. gpu.set(x, y + self.h - 1, unicode.char(0x21E9))
  495. end
  496. end
  497. local proz = math.floor(100 / (self.max - self.min) * (self.value - self.min))
  498. if proz > 100 then
  499. proz = 100
  500. end
  501. local pos = math.floor((self.h - 3) / 100 * proz)
  502. if y + pos + 1 < win.y + win.h then
  503. if x < win.x + win.w - 1 then
  504. gpu.setBackground(self.foreground)
  505. gpu.set(x, y + pos + 1, " ")
  506. end
  507. end
  508. end
  509.  
  510. function drawHSlider(win, self)
  511. gpu.setBackground(self.background)
  512. gpu.setForeground(self.foreground)
  513. local x, y, w, h = correctPos(win, self)
  514. gpu.fill(x + 1, y, w - 1, h, " ")
  515. if y < win.y + win.h then
  516. if x < win.x + win.w - 1 then
  517. gpu.set(x, y, unicode.char(0x21E6))
  518. end
  519. if x + self.w < win.x + win.w then
  520. gpu.set(x + self.w - 1, y, unicode.char(0x21E8))
  521. end
  522. local proz = math.floor(100 / (self.max - self.min) * (self.value - self.min))
  523. if proz > 100 then
  524. proz = 100
  525. end
  526. local pos = math.floor((self.w - 3) / 100 * proz) + 1
  527. if x + pos < win.x + win.w - 1 then
  528. gpu.setBackground(self.foreground)
  529. gpu.fill(x + pos, y, 1, h , " ")
  530. end
  531. end
  532. end
  533.  
  534. function drawHBar(win, self)
  535. gpu.setBackground(self.background)
  536. gpu.setForeground(self.foreground)
  537. local x, y, w, h = correctPos(win, self)
  538. gpu.fill(x + 1, y, w - 1, h, " ")
  539. if y < win.y + win.h then
  540. local proz = math.floor(100 / (self.max - self.min) * (self.value - self.min))
  541. if proz > 100 then
  542. proz = 100
  543. end
  544. local pos = math.floor(self.w / 100 * proz)
  545. gpu.setBackground(self.foreground)
  546. if x + pos < win.x + win.w - 1 then
  547. gpu.fill(x, y, pos, 1, " ")
  548. else
  549. gpu.fill(x, y, win.x + win.w - 1 - x, 1, " ")
  550. end
  551. end
  552. end
  553.  
  554. function drawFrame(win, self)
  555. gpu.setBackground(self.background)
  556. gpu.setForeground(self.foreground)
  557. local x, y, w, h = correctPos(win, self)
  558. local tmpFrame = {}
  559. if self.type == 1 then
  560. tmpFrame = Frame.Small
  561. elseif self.type == 2 then
  562. tmpFrame = Frame.Double
  563. elseif self.type == 3 then
  564. tmpFrame = Frame.Bold
  565. end
  566. if y < win.y + win.h then
  567. gpu.fill(x + 1, y, w - 1, 1, unicode.char(tmpFrame[1])) -- top
  568. end
  569. if y + h < win.y + win.h then
  570. gpu.fill(x + 1, y + h, w - 1, 1, unicode.char(tmpFrame[1])) -- bottom
  571. end
  572. if y < win.y + win.h and x < win.x + win.w - 1 then
  573. gpu.set(x, y, unicode.char(tmpFrame[3])) -- left-top
  574. end
  575. if y + h < win.y + win.h and x < win.x + win.w - 1 then
  576. gpu.set(x, y + h, unicode.char(tmpFrame[5])) -- left-bottom
  577. end
  578. if x < win.x + win.w - 1 then
  579. gpu.fill(x, y + 1, 1, h - 1, unicode.char(tmpFrame[2])) -- left
  580. end
  581.  
  582. if y < win.y + win.h and x + self.w < win.x + win.w then
  583. gpu.set(x + w - 1, y, unicode.char(tmpFrame[4])) -- right-top
  584. end
  585. if y + h < win.y + win.h and x + self.w < win.x + win.w then
  586. gpu.set(x + w - 1, y + h, unicode.char(tmpFrame[6])) -- right-bottom
  587. end
  588. if x + self.w < win.x + win.w then
  589. gpu.fill(x + w - 1, y + 1, 1, h - 1, unicode.char(tmpFrame[2])) -- right
  590. end
  591. end
  592.  
  593. function drawLine(win, self)
  594. gpu.setBackground(self.background)
  595. gpu.setForeground(self.foreground)
  596. local x, y, w, h = correctPos(win, self)
  597. if self.type == 1 then
  598. gpu.fill(x, y, w, h, unicode.char(0x2500))
  599. elseif self.type == 2 then
  600. gpu.fill(x, y, w, h, unicode.char(0x2550))
  601. elseif self.type == 3 then
  602. gpu.fill(x, y, w, h, unicode.char(0x2501))
  603. elseif self.type == 4 then
  604. gpu.fill(x, y, w, h, ".")
  605. elseif self.type == 5 then
  606. gpu.fill(x, y, w, h, "-")
  607. elseif self.type == 6 then
  608. gpu.fill(x, y, w, h, "=")
  609. elseif self.type == 7 then
  610. gpu.fill(x, y, w, h, " ")
  611. elseif self.type == 8 then
  612. gpu.fill(x, y, w, h, ".")
  613. for i = 4, w, 5 do
  614. if i + x < win.x + win.w - 1 then
  615. gpu.set(i + x, y, ":")
  616. end
  617. end
  618. end
  619. end
  620.  
  621.  
  622. function drawLabel(win, self)
  623. local x, y, w, h = correctPos(win, self)
  624. if self.isActive == true then
  625. gpu.setBackground(self.activeBackground)
  626. gpu.setForeground(self.activeForeground)
  627. self.isActive = false
  628. else
  629. gpu.setBackground(self.background)
  630. gpu.setForeground(self.foreground)
  631. self.isActive = false
  632. end
  633. gpu.fill(x, y, w, h, " ")
  634. local tPos = getPosAlign(win, self)
  635. if self.autoWordWrap == true then
  636. local text = wrap(self.text, self.w)
  637. for i = 1, #text do
  638. if h >= 1 and i <= h then
  639. local sl = (tPos + string.len(text[i]))
  640. if sl > x + w then
  641. sl = x + w - sl - 1
  642. end
  643. if tPos <= win.x + win.w - 2 then
  644. gpu.set(tPos, y + i - 1, string.sub(text[i], 1, sl))
  645. end
  646. end
  647. end
  648. else
  649. if h >= 1 then
  650. local sl = (tPos + string.len(self.text))
  651. if sl > x + w then
  652. sl = x + w - sl - 1
  653. end
  654. if tPos <= win.x + win.w - 2 then
  655. gpu.set(tPos, y, string.sub(self.text, 1, sl))
  656. end
  657. end
  658. end
  659. end
  660.  
  661.  
  662. -- handle callbacks
  663. function generalCallback(win, self, x, y, b)
  664. updateLastElement(self)
  665. end
  666.  
  667. function handleTerminal(win, self, x, y, b)
  668. end
  669.  
  670. function handleList(win, self, x, y, b)
  671. updateLastElement(self)
  672. local sx, sy, sw, sh = correctPos(win, self)
  673. if b == 0 then
  674. self.selected = self.selected + y - sy
  675. end
  676. drawList(win, self)
  677. end
  678.  
  679. function handleRadio(win, self, x, y, b)
  680. updateLastElement(self)
  681. local sx, sy, sw, sh = correctPos(win, self)
  682. if b == 0 then
  683. if self.alignment == "left" then
  684. if x == sx + string.len(self.data[y - sy + 1]) + 2 then
  685. self.selected = y - sy + 1
  686. end
  687. elseif self.alignment == "right" then
  688. if x == sx + 1 then
  689. self.selected = y - sy + 1
  690. end
  691. end
  692. end
  693. drawRadio(win, self)
  694. end
  695.  
  696. function handleInput(win, self, x, y, b)
  697. updateLastElement(self)
  698. local sx, sy, sw, sh = correctPos(win, self)
  699. if b == 0 then
  700. if self.isActive == false then
  701. self.isActive = true
  702. drawInput(win, self)
  703. local inputText = self.text
  704. local cursorState = false
  705. while self.isActive == true do
  706. local tmpText = inputText
  707. if self.protected == true then
  708. tmpText = ""
  709. for i = 1, string.len(inputText) do
  710. tmpText = tmpText .. "*"
  711. end
  712. end
  713. gpu.setBackground(self.activeBackground)
  714. gpu.setForeground(self.activeForeground)
  715. gpu.fill(sx, sy, sw, 1, " ")
  716. if string.len(tmpText) + 1 > sw then
  717. tmpText = string.sub(tmpText, string.len(tmpText) - sw + 2, string.len(tmpText))
  718. end
  719. if cursorState == true then
  720. cursorState = false
  721. tmpText = tmpText .. unicode.char(0x2582)
  722. else
  723. cursorState = true
  724. end
  725. gpu.set(sx, sy, tmpText)
  726. local ev, _, ch, num = event.pullMultiple(0.1, "key_down", "touch")
  727. if ev == "key_down" then
  728. if ch == 13 then -- return
  729. self.text = inputText
  730. self.isActive = false
  731. if win == wm.getActiveWindow() then
  732. drawInput(win, self)
  733. end
  734. elseif ch == 8 then -- backspace
  735. inputText = string.sub(inputText, 1, string.len(inputText) - 1)
  736. elseif ch > 31 and ch < 128 then -- all other characters
  737. inputText = inputText .. string.char(ch)
  738. end
  739. elseif ev == "touch" then
  740. if ch < sx or ch > sx + sw - 1 or num < sy or num > sy then
  741. self.text = inputText
  742. self.isActive = false
  743. if win == wm.getActiveWindow() then
  744. drawInput(win, self)
  745. end
  746. end
  747. end
  748. end
  749. end
  750. self.isActive = false
  751. end
  752. if b == 1 then
  753. return false
  754. end
  755. -- gpu.set(1,25, self.callback)
  756. -- if self.callback then
  757. -- self.callback(self, win) -- we need to call the callback, or user has no callback after text editing
  758. -- end
  759. return true
  760. end
  761.  
  762. function handleCheckbox(win, self, x, y, b)
  763. updateLastElement(self)
  764. local sx, sy, sw, sh = correctPos(win, self)
  765. if b == 0 then
  766. if x == sx + 1 and y == sy and self.alignment == "right" then
  767. self.state = not self.state
  768. drawCheckbox(win, self)
  769. elseif x == sx + string.len(self.text) + 2 and y == sy and self.alignment == "left" then
  770. self.state = not self.state
  771. drawCheckbox(win, self)
  772. end
  773. end
  774. if b == 1 then
  775. return false
  776. end
  777. return true
  778. end
  779.  
  780.  
  781. function handleButton(win, self, x, y, b)
  782. updateLastElement(self)
  783. if b == 0 then
  784. -- just let the user know, that the button was pressed
  785. self.isActive = true
  786. drawLabel(win, self)
  787. os.sleep(0.1)
  788. self.isActive = false
  789. drawLabel(win, self)
  790. end
  791. if b == 1 then
  792. return false
  793. end
  794. return true
  795. end
  796.  
  797. function handleVSlider(win, self, x, y, b)
  798. updateLastElement(self)
  799. local sx, sy, sw, sh = correctPos(win, self)
  800. if b == 0 then
  801. if x == sx and y == sy then
  802. gpu.setBackground(self.activeBackground)
  803. gpu.setForeground(self.activeForeground)
  804. gpu.set(sx, sy, unicode.char(0x21E7))
  805. os.sleep(0.1)
  806. gpu.setBackground(self.background)
  807. gpu.setForeground(self.foreground)
  808. gpu.set(sx, sy, unicode.char(0x21E7))
  809. self.value = self.value - self.steps
  810. if self.value < self.min then
  811. self.value = self.min
  812. end
  813. drawVSlider(win, self)
  814. end
  815. if x == sx and y == sy + self.h -1 then
  816. gpu.setBackground(self.activeBackground)
  817. gpu.setForeground(self.activeForeground)
  818. gpu.set(sx, sy + self.h - 1, unicode.char(0x21E9))
  819. os.sleep(0.1)
  820. gpu.setBackground(self.background)
  821. gpu.setForeground(self.foreground)
  822. gpu.set(sx, sy + self.h - 1, unicode.char(0x21E9))
  823. self.value = self.value + self.steps
  824. if self.value > self.max then
  825. self.value = self.max
  826. end
  827. drawVSlider(win, self)
  828. end
  829. end
  830. if b == 1 then
  831. return false
  832. end
  833. return true
  834. end
  835.  
  836.  
  837. function handleHSlider(win, self, x, y, b)
  838. updateLastElement(self)
  839. local sx, sy, sw, sh = correctPos(win, self)
  840. if b == 0 then
  841. if x == sx and y == sy then -- left arrow pressed
  842. gpu.setBackground(self.activeBackground)
  843. gpu.setForeground(self.activeForeground)
  844. gpu.set(sx, sy, unicode.char(0x21E6))
  845. os.sleep(0.1)
  846. gpu.setBackground(self.background)
  847. gpu.setForeground(self.foreground)
  848. gpu.set(sx, sy, unicode.char(0x21E6))
  849. self.value = self.value - self.steps
  850. if self.value < self.min then
  851. self.value = self.min
  852. end
  853. drawHSlider(win, self)
  854. end
  855. if x == sx + self.w - 1 and y == sy then -- right arrow pressed
  856. gpu.setBackground(self.activeBackground)
  857. gpu.setForeground(self.activeForeground)
  858. gpu.set(sx + self.w - 1, sy, unicode.char(0x21E8))
  859. os.sleep(0.1)
  860. gpu.setBackground(self.background)
  861. gpu.setForeground(self.foreground)
  862. gpu.set(sx + self.w - 1, sy, unicode.char(0x21E8))
  863. self.value = self.value + self.steps
  864. if self.value > self.max then
  865. self.value = self.max
  866. end
  867. drawHSlider(win, self)
  868. end
  869. end
  870. if b == 1 then
  871. return false
  872. end
  873. return true
  874. end
  875.  
  876. -- contructors
  877. function guiElements.newTerminal(x, y, w, h)
  878. self = wm.newElement("terminal", x, y, w, h)
  879. self.drawCallback = drawTerminal
  880. self.background = Color.TerminalBackground
  881. self.foreground = Color.TerminalForeground
  882. self.handleCallback = handleTerminal
  883. return self
  884. end
  885.  
  886. function guiElements.newDrawBuffer(x, y, w, h)
  887. self = wm.newElement("drawbuffer", x, y, w, h)
  888. self.drawCallback = drawBuffer
  889. self.background = Color.DrawBufferBackground
  890. self.foreground = Color.DrawBufferForeground
  891. self.handleCallback = generalCallback
  892. self.userData1.xv = 0
  893. self.userData1.yv = 0
  894. self.userData2.oldXV = 0
  895. self.userData2.oldYV = 0
  896. self.data = {}
  897. for i = 1, 160 do
  898. self.data[i] = {}
  899. for j = 1, 50 do
  900. self.data[i][j] = {["bg"] = Color.DrawBufferBackground, ["fg"] = Color.DrawBufferForeground, ["character"] = "."}
  901. end
  902. end
  903. return self
  904. end
  905.  
  906. function guiElements.newRadioGroup(x, y, w, callback)
  907. self = wm.newElement("radio", x, y, w, 1, nil, callback)
  908. self.drawCallback = drawRadio
  909. self.background = Color.RadioBackground
  910. self.foreground = Color.RadioForeground
  911. self.handleCallback = handleRadio
  912. return self
  913. end
  914.  
  915. function guiElements.newList(x, y, w, h, text, callback)
  916. self = wm.newElement("list", x, y, w, h, text, callback)
  917. self.drawCallback = drawList
  918. self.background = Color.ListBackground
  919. self.foreground = Color.ListForeground
  920. self.activeBackground = Color.ListActiveBackground
  921. self.activeForeground = Color.ListActiveForeground
  922. self.handleCallback = handleList
  923. return self
  924. end
  925.  
  926. function guiElements.newInput(x, y, w, text, callback)
  927. self = wm.newElement("input", x, y, w, 1, text, callback)
  928. self.drawCallback = drawInput
  929. self.background = Color.InputBackground
  930. self.foreground = Color.InputForeground
  931. self.activeBackground = Color.InputActiveBackground
  932. self.activeForeground = Color.InputActiveForeground
  933. self.handleCallback = handleInput
  934. return self
  935. end
  936.  
  937. function guiElements.newCheckbox(x, y, text, callback)
  938. self = wm.newElement("checkbox", x, y, string.len(text) + 4, 1, text, callback)
  939. self.drawCallback = drawCheckbox
  940. self.background = Color.CheckboxBackground
  941. self.foreground = Color.CheckboxForeground
  942. self.handleCallback = handleCheckbox
  943. return self
  944. end
  945.  
  946. function guiElements.newHBar(x, y, w, h)
  947. self = wm.newElement("hbar", x, y, w, h)
  948. self.drawCallback = drawHBar
  949. self.background = Color.HBarBackground
  950. self.foreground = Color.HBarForeground
  951. self.handleCallback = generalCallback
  952. return self
  953. end
  954.  
  955. function guiElements.newVSlider(x, y, h, callback)
  956. self = wm.newElement("vslider", x, y, 1, h, "", callback)
  957. self.drawCallback = drawVSlider
  958. self.background = Color.VSliderBackground
  959. self.foreground = Color.VSliderForeground
  960. self.activeBackground = Color.VSliderActiveBackground
  961. self.activeForeground = Color.VSliderActiveForeground
  962. self.handleCallback = handleVSlider
  963. return self
  964. end
  965.  
  966. function guiElements.newHSlider(x, y, w, callback)
  967. self = wm.newElement("hslider", x, y, w, 1, "", callback)
  968. self.drawCallback = drawHSlider
  969. self.background = Color.HSliderBackground
  970. self.foreground = Color.HSliderForeground
  971. self.activeBackground = Color.HSliderActiveBackground
  972. self.activeForeground = Color.HSliderActiveForeground
  973. self.handleCallback = handleHSlider
  974. return self
  975. end
  976.  
  977. function guiElements.newFrame(x, y, w, h)
  978. self = wm.newElement("frame", x, y, w, h - 1) --FIXME: NO! FUCK IT! Size correction in draw function is more complicated, then this
  979. self.drawCallback = drawFrame
  980. self.background = Color.FrameBackground
  981. self.foreground = Color.FrameForeground
  982. self.handleCallback = generalCallback
  983. return self
  984. end
  985.  
  986. function guiElements.newLine(x, y, w)
  987. self = wm.newElement("line", x, y, w)
  988. self.drawCallback = drawLine
  989. self.background = Color.LabelBackground
  990. self.foreground = Color.LabelForeground
  991. self.handleCallback = generalCallback
  992. return self
  993. end
  994.  
  995. function guiElements.newLabel(x, y, w, h, text)
  996. self = wm.newElement("label", x, y, w, h, text)
  997. self.drawCallback = drawLabel
  998. self.background = Color.LabelBackground
  999. self.foreground = Color.LabelForeground
  1000. self.alignment = "left"
  1001. self.handleCallback = generalCallback
  1002. return self
  1003. end
  1004.  
  1005. function guiElements.newButton(x, y, w, h, text, callback)
  1006. self = wm.newElement("button", x, y, w, h, text, callback)
  1007. self.drawCallback = drawLabel
  1008. self.background = Color.ButtonBackground
  1009. self.foreground = Color.ButtonForeground
  1010. self.activeBackground = Color.ButtonActiveBackground
  1011. self.activeForeground = Color.ButtonActiveForeground
  1012. self.alignment = "center"
  1013. self.handleCallback = handleButton
  1014. return self
  1015. end
  1016.  
  1017.  
  1018. function guiElements.drawElement(win, self)
  1019. if win.moving == false then
  1020. self.drawCallback(win, self)
  1021. end
  1022. end
  1023.  
  1024. function guiElements.setElementBackground(self, background)
  1025. self.background = background
  1026. end
  1027.  
  1028. function guiElements.setElementForeground(self, foreground)
  1029. self.foreground = foreground
  1030. end
  1031.  
  1032. function guiElements.setElementActiveBackground(self, background)
  1033. self.activeBackground = background
  1034. end
  1035.  
  1036. function guiElements.setElementActiveForeground(self, foreground)
  1037. self.activeForeground = foreground
  1038. end
  1039.  
  1040. function guiElements.setElementX(self, x)
  1041. self.x = x
  1042. end
  1043.  
  1044. function guiElements.setElementY(self, y)
  1045. self.y = y
  1046. end
  1047.  
  1048. function guiElements.setElementW(self, w)
  1049. self.w = w
  1050. end
  1051.  
  1052. function guiElements.setElementH(self, h)
  1053. self.h = h
  1054. end
  1055.  
  1056. function guiElements.setElementText(self, text)
  1057. self.text = text
  1058. end
  1059.  
  1060. function guiElements.setElementCallback(self, callback)
  1061. self.callback = callback
  1062. end
  1063.  
  1064. function guiElements.setElementHandleCallback(self, callback)
  1065. self.handleCallback = callback
  1066. end
  1067.  
  1068. function guiElements.setElementDrawCallback(self, callback)
  1069. self.drawCallback = callback
  1070. end
  1071.  
  1072. function guiElements.setElementAlignment(self, alignment)
  1073. self.alignment = alignment
  1074. end
  1075.  
  1076. function guiElements.setElementType(self, type)
  1077. self.type = type
  1078. end
  1079.  
  1080. function guiElements.newElement(id, x, y, w, h, text)
  1081. return wm.newElement(id, x, y, w, h, text)
  1082. end
  1083.  
  1084. function guiElements.setElementMax(self, max)
  1085. self.max = max
  1086. end
  1087.  
  1088. function guiElements.setElementMin(self, min)
  1089. self.min = min
  1090. end
  1091.  
  1092. function guiElements.setElementValue(self, value)
  1093. self.value = value
  1094. end
  1095.  
  1096. function guiElements.setElementState(self, state)
  1097. self.state = state
  1098. end
  1099.  
  1100. function guiElements.setElementSteps(self, steps)
  1101. self.steps = steps
  1102. end
  1103.  
  1104. function guiElements.setElementAutoWordWrap(self, state)
  1105. self.autoWordWrap = state
  1106. end
  1107.  
  1108. function guiElements.insertElementData(self, data)
  1109. table.insert(self.data, data)
  1110. self.last = self.last + 1
  1111. end
  1112.  
  1113. function guiElements.removeElementData(self, num)
  1114. table.remove(self.data, num)
  1115. self.last = self.last - 1
  1116. end
  1117.  
  1118. function guiElements.changeElementData(self, num, data)
  1119. self.data[num] = data
  1120. end
  1121.  
  1122. function guiElements.clearElementData(self)
  1123. self.data = {}
  1124. self.last = 1
  1125. self.selected = 1
  1126. self.first = 1
  1127. end
  1128.  
  1129.  
  1130. function guiElements.getElementBackground(self)
  1131. return self.background
  1132. end
  1133.  
  1134. function guiElements.getElementForeground(self)
  1135. return self.foreground
  1136. end
  1137.  
  1138. function guiElements.getElementActiveBackground(self)
  1139. return self.activeBackground
  1140. end
  1141.  
  1142. function guiElements.getElementActiveForeground(self)
  1143. return self.activeForeground
  1144. end
  1145.  
  1146. function guiElements.getElementX(self)
  1147. return self.x
  1148. end
  1149.  
  1150. function guiElements.getElementY(self)
  1151. return self.y
  1152. end
  1153.  
  1154. function guiElements.getElementW(self)
  1155. return self.w
  1156. end
  1157.  
  1158. function guiElements.getElementH(self, h)
  1159. return self.h
  1160. end
  1161.  
  1162. function guiElements.getElementText(self)
  1163. return self.text
  1164. end
  1165.  
  1166. function guiElements.getElementAlignment(self)
  1167. return self.alignment
  1168. end
  1169.  
  1170. function guiElements.getElementMax(self)
  1171. return self.max
  1172. end
  1173.  
  1174. function guiElements.getElementMin(self)
  1175. return self.min
  1176. end
  1177.  
  1178. function guiElements.getElementValue(self)
  1179. return self.value
  1180. end
  1181.  
  1182. function guiElements.getElementState(self)
  1183. return self.state
  1184. end
  1185.  
  1186. function guiElements.getElementAutoWordWrap(self)
  1187. return self.autoWordWrap
  1188. end
  1189.  
  1190. function guiElements.getElementType(self)
  1191. return self.type
  1192. end
  1193.  
  1194. function guiElements.getLastElement()
  1195. return lastElement
  1196. end
  1197.  
  1198. function guiElements.setElementIgnoreMouseBlock(self, state)
  1199. self.ignoreMouseBlock = state
  1200. end
  1201.  
  1202. function guiElements.setElementUserData1(self, data)
  1203. self.userData1 = data
  1204. end
  1205.  
  1206. function guiElements.setElementUserData2(self, data)
  1207. self.userData2 = data
  1208. end
  1209.  
  1210. function guiElements.setElementUserData3(self, data)
  1211. self.userData3 = data
  1212. end
  1213.  
  1214. function guiElements.getElementUserData1(self)
  1215. return self.userData1
  1216. end
  1217.  
  1218. function guiElements.getElementUserData2(self)
  1219. return self.userData2
  1220. end
  1221.  
  1222. function guiElements.getElementUserData3(self)
  1223. return self.userData3
  1224. end
  1225.  
  1226. function guiElements.setElementProtected(self, state)
  1227. self.protected = state
  1228. end
  1229.  
  1230. function guiElements.getElementProtected(self)
  1231. return self.protected
  1232. end
  1233.  
  1234. function guiElements.setElementSelected(self, state)
  1235. self.selected = state
  1236. end
  1237.  
  1238. function guiElements.getElementSelected(self)
  1239. return self.selected
  1240. end
  1241.  
  1242. function guiElements.getColors()
  1243. return Color
  1244. end
  1245.  
  1246.  
  1247.  
  1248. local function getFiles(path)
  1249. path = filesystem.canonical(path)
  1250. local ft = {}
  1251. local dt = {}
  1252. for file in filesystem.list(path) do
  1253. if string.sub(file, string.len(file)) == "/" then
  1254. table.insert(dt, file)
  1255. else
  1256. table.insert(ft, file)
  1257. end
  1258. end
  1259. table.sort(ft)
  1260. table.sort(dt)
  1261.  
  1262. local fs = {}
  1263. for k,v in pairs(dt) do
  1264. table.insert(fs,v)
  1265. end
  1266. for k,v in pairs(ft) do
  1267. table.insert(fs,v)
  1268. end
  1269. if path == "/" then
  1270. return fs, nil
  1271. else
  1272. return fs, true
  1273. end
  1274. end
  1275.  
  1276. local ScreenWidth, screenHeight = gpu.getResolution()
  1277.  
  1278. local files, List, Slider, window, selected, running, Path, filenameInput
  1279.  
  1280. local function reloadFileList(path)
  1281. files = getFiles(path)
  1282. guiElements.clearElementData(List)
  1283. for i = 1, #files do
  1284. guiElements.insertElementData(List, files[i])
  1285. end
  1286.  
  1287. selected = 1
  1288. guiElements.setElementMax(Slider, #files)
  1289. guiElements.setElementValue(Slider, 1)
  1290. guiElements.setElementText(pathLabel, filesystem.canonical(path))
  1291. guiElements.drawElement(window, Slider)
  1292. guiElements.drawElement(window, List)
  1293. guiElements.drawElement(window, pathLabel)
  1294. end
  1295.  
  1296. local function goBackCallback(self, win)
  1297. if Path ~= "/" then
  1298. Path = string.sub(Path, 1, #Path - Path:reverse():find("/") ) -- go one path back
  1299. reloadFileList(Path)
  1300. end
  1301. end
  1302.  
  1303. local function listCallback(self, win)
  1304. selected = guiElements.getElementSelected(self)
  1305. newPath = filesystem.canonical(Path .. "/" .. string.sub(files[selected], 1, string.len(files[selected])))
  1306. if filesystem.isDirectory(newPath) then
  1307. Path = newPath
  1308. reloadFileList(Path)
  1309. else
  1310. local FileName = filesystem.name(newPath)
  1311. if FileName == nil then
  1312. FileName = ""
  1313. end
  1314. guiElements.setElementText(filenameInput, FileName)
  1315. guiElements.drawElement(window, filenameInput)
  1316. end
  1317. end
  1318.  
  1319. function guiElements.fileSelect(param)
  1320. if param == nil then
  1321. param = "Select file"
  1322. end
  1323. local windowWidth = 40
  1324. local windowHeight = 21
  1325. local running = true
  1326. local canceled = false
  1327.  
  1328. window = wm.newWindow(math.floor(ScreenWidth/2) - math.floor(windowWidth/2), math.floor(screenHeight/2) - math.floor(windowHeight/2), windowWidth, windowHeight, param)
  1329. wm.disableWindowButtons(window, true)
  1330. wm.hideWindow(window, hideWindowFromList)
  1331.  
  1332. pathLabel = guiElements.newLabel(2, 1, 38, 1, "")
  1333. wm.addElement(window, pathLabel)
  1334.  
  1335. wm.addElement(window, guiElements.newLine(1, 2, 38))
  1336.  
  1337. List = guiElements.newList(2, 3, 35, 14, "", listCallback)
  1338. guiElements.clearElementData(List)
  1339. wm.addElement(window, List)
  1340. guiElements.setElementBackground(List, 0xFFFFFF)
  1341. guiElements.setElementActiveBackground(List, 0x202020)
  1342. guiElements.setElementForeground(List, 0x000000)
  1343. guiElements.setElementActiveForeground(List, 0xFFFFFF)
  1344.  
  1345.  
  1346. Slider = guiElements.newVSlider(37, 3, 14, function() selected = guiElements.getElementValue(Slider) guiElements.setElementSelected(List, selected) guiElements.drawElement(window, List) end)
  1347. guiElements.setElementMin(Slider, 1)
  1348. guiElements.setElementValue(Slider, 1)
  1349. wm.addElement(window, Slider)
  1350.  
  1351. wm.addElement(window, guiElements.newLine(1, 17, 38))
  1352.  
  1353. wm.addElement(window, guiElements.newLabel(2, 18, 10, 1, "Filename "))
  1354. filenameInput = guiElements.newInput(11, 18, 27, "")
  1355. wm.addElement(window, filenameInput)
  1356.  
  1357. wm.addElement(window, guiElements.newLine(1, 19, 38))
  1358.  
  1359. local upButton = guiElements.newButton(2, windowHeight - 1, 4, 1, "up", goBackCallback)
  1360. wm.addElement(window, upButton)
  1361.  
  1362. local cancelButton = guiElements.newButton(20, windowHeight - 1, 7, 1, "cancel", function()wm.closeWindow(window) canceled = true running = false end)
  1363. wm.addElement(window, cancelButton)
  1364.  
  1365. local selectButton = guiElements.newButton(30, windowHeight - 1, 7, 1, "select", function()wm.closeWindow(window) canceled = false running = false end)
  1366. wm.addElement(window, selectButton)
  1367.  
  1368. reloadFileList("/")
  1369. Path = "/"
  1370.  
  1371. wm.raiseWindow(window)
  1372.  
  1373. while running == true do
  1374. os.sleep(0.00001)
  1375. end
  1376. if canceled == false then
  1377. return true, filesystem.canonical(Path .. "/" .. guiElements.getElementText(filenameInput))
  1378. else
  1379. return false
  1380. end
  1381. end
  1382.  
  1383. function guiElements.checkComponent(comp)
  1384. local errorWindowWidth = 40
  1385. local errorWindowHeight = 6
  1386. if component.isAvailable(comp) == false then
  1387. gpu.set(1,2, comp)
  1388. errorWindow = wm.newWindow(math.floor(ScreenWidth/2) - math.floor(errorWindowWidth/2), math.floor(screenHeight/2) - math.floor(errorWindowHeight/2), errorWindowWidth, errorWindowHeight, "Component missing")
  1389. wm.disableWindowButtons(errorWindow, true)
  1390. wm.setWindowSticky(errorWindow, true)
  1391.  
  1392. local t = "No " .. comp .. " found"
  1393. local errorLabel = guiElements.newLabel(2, 2, errorWindowWidth - 4, 1, t)
  1394. guiElements.setElementForeground(errorLabel, 0xFF0000)
  1395. guiElements.setElementAlignment(errorLabel, "center")
  1396. wm.addElement(errorWindow, errorLabel)
  1397.  
  1398. local closeButton = guiElements.newButton(math.floor(errorWindowWidth/2) - 4, errorWindowHeight - 1, 7, 1, "close", function() wm.closeWindow(errorWindow) end)
  1399. wm.addElement(errorWindow, closeButton)
  1400.  
  1401. wm.raiseWindow(errorWindow)
  1402.  
  1403. return false
  1404. end
  1405. return true
  1406. end
  1407.  
  1408. return guiElements
Add Comment
Please, Sign In to add comment