Advertisement
kaibochan

case_0.lua

Feb 19th, 2025 (edited)
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.77 KB | None | 0 0
  1. local gui = require("/apis/gui")
  2.  
  3. function main()
  4.     local monitor_0 = peripheral.wrap("monitor_0")
  5.     local monitor_5 = peripheral.wrap("monitor_5")
  6.  
  7.     monitor_0.setTextScale(1)
  8.     monitor_0.clear()
  9.     monitor_0.setCursorPos(1, 1)
  10.  
  11.     monitor_5.setTextScale(0.5)
  12.     monitor_5.clear()
  13.     monitor_5.setCursorPos(1, 1)
  14.  
  15.     -- initialize display using above information
  16.     -- receive buffer object which elements can be added to
  17.     local text_display = gui.initializeDisplay(monitor_0)
  18.     local debug_display = gui.initializeDisplay(monitor_5)
  19.  
  20.     setupDisplays(text_display, debug_display)  
  21.    
  22.     while true do
  23.         text_display:render()
  24.         debug_display:render()
  25.         gui.doEvents()
  26.     end
  27. end
  28.  
  29. function setupDisplays(text_display, debug_display)
  30.     local w, h = debug_display.window:getSize()
  31.     local debug_log = gui.Text:new {
  32.         width = w,
  33.         height = h,
  34.         auto_scroll = true,
  35.     }
  36.     debug_display.window:addElement(debug_log)
  37.  
  38.     local text_container = gui.Element:new {
  39.         x = 1,
  40.         y = 1,
  41.         width = 21,
  42.         height = 12,
  43.         bg_color = colors.gray,
  44.     }
  45.     text_display.window:addElement(text_container)
  46.  
  47.     local filler_text = gui.Text:new {
  48.         x = 1,
  49.         y = 1,
  50.         width = 18,
  51.         height = 10,
  52.         bg_color = colors.white,
  53.  
  54.         text = "lorem ipsum dolor sit amet",
  55.         text_color = colors.black,
  56.  
  57.         monitor_touch = function(self, e)
  58.             debug_log:write(self.__name .. "\n")
  59.         end,
  60.     }
  61.     text_container:addElement(filler_text)
  62.    
  63.     -- another way to attach the same callback function
  64.     -- function filler_text:monitor_touch(e)
  65.     --     debug_log:write(self.__name .. "\n")
  66.     -- end
  67.  
  68.     local scroll_bar_container = gui.Element:new {
  69.         x = 19,
  70.         y = 1,
  71.         width = 1,
  72.         height = 10,
  73.         bg_color = colors.lightGray,
  74.     }
  75.     text_container:addElement(scroll_bar_container)
  76.  
  77.     local scroll_up_button = gui.Element:new {
  78.         x = 0,
  79.         y = 0,
  80.         width = 1,
  81.         height = 1,
  82.         bg_color = colors.red,
  83.  
  84.         monitor_touch = function(self, e)
  85.             debug_log:write(self.__name .. "\n")
  86.             filler_text.scroll_offset = filler_text.scroll_offset - 1
  87.         end,
  88.     }
  89.     scroll_bar_container:addElement(scroll_up_button)
  90.  
  91.     local scroll_down_button = gui.Element:new {
  92.         x = 0,
  93.         y = 9,
  94.         width = 1,
  95.         height = 1,
  96.         bg_color = colors.green,
  97.  
  98.         monitor_touch = function(self, e)
  99.             debug_log:write(self.__name .. "\n")
  100.             filler_text.scroll_offset = filler_text.scroll_offset + 1
  101.         end,
  102.     }
  103.     scroll_bar_container:addElement(scroll_down_button)
  104. end
  105.  
  106. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement