Advertisement
kaibochan

testgui.lua

Mar 20th, 2023 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.95 KB | None | 0 0
  1. local gui = require "gui"
  2.  
  3. local buffer = createBuffer(term, "buffer", colors.pink)
  4.  
  5. local button1 = Text:new {
  6.     name = "button1",
  7.     buffer = buffer,
  8.     parent = buffer,
  9.     x = 2,
  10.     text = "lorem ipsum",
  11.     horizontalAlignment = align.center,
  12.     verticalAlignment = align.center,
  13.     backgroundColor = colors.red,
  14.     width = 11,
  15.     height = 1,
  16.     padding = 0,
  17. }
  18.  
  19. registerSelectionCallback("mouse_click", button1, function(element, event, button, x, y)
  20.     if button == 1 then
  21.         button1:setBackgroundColor(2^math.random(15))
  22.     end
  23. end, "buttonClick")
  24.  
  25. local button2 = Text:new {
  26.     name = "button2",
  27.     buffer = buffer,
  28.     parent = buffer,
  29.     x = 2,
  30.     y = 3,
  31.     text = "kaibochan",
  32.     horizontalAlignment = align.center,
  33.     verticalAlignment = align.center,
  34.     backgroundColor = colors.blue,
  35.     width = 11,
  36.     height = 1,
  37.     padding = 0,
  38. }
  39.  
  40. registerSelectionCallback("mouse_click", button2, function(element, event, button, x, y)
  41.     if button == 1 then
  42.         button2:setBackgroundColor(2^math.random(15))
  43.     elseif button == 2 then
  44.         button2:setTextColor(2^math.random(15))
  45.     end
  46. end, "buttonClick")
  47.  
  48. local textBox = Textbox:new {
  49.     name = "textBox1",
  50.     buffer = buffer,
  51.     parent = buffer,
  52.     x = 25,
  53.     y = 2,
  54.     width = 20,
  55.     height = 5,
  56.     backgroundColor = colors.red,
  57.     textColor = colors.orange,
  58. }
  59.  
  60. local text = Text:new {
  61.     name = "text",
  62.     x = 2,
  63.     y = 2,
  64.     width = 5,
  65.     height = 2,
  66.     text = "Lorem ipsum dolor sit amet."
  67. }
  68.  
  69. local textBox2 = Textbox:new {
  70.     name = "textBox2",
  71.     x = 8,
  72.     y = 3,
  73.     width = 10,
  74.     height = 3,
  75.     padding = 0,
  76. }
  77.  
  78. local window = Window:new {
  79.     name = "window",
  80.     buffer = buffer,
  81.     parent = buffer,
  82.     x = 1,
  83.     y = 5,
  84.     width = 20,
  85.     height = 10,
  86.     contents = { text, textBox2 },
  87. }
  88.  
  89.  
  90.  
  91. while true do
  92.     buffer:draw()
  93.  
  94.     parallel.waitForAny(handleInputEvents())
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement