Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local gui = require("/apis/gui")
- function main()
- local monitor_0 = peripheral.wrap("monitor_0")
- local monitor_5 = peripheral.wrap("monitor_5")
- monitor_0.setTextScale(1)
- monitor_0.clear()
- monitor_0.setCursorPos(1, 1)
- monitor_5.setTextScale(0.5)
- monitor_5.clear()
- monitor_5.setCursorPos(1, 1)
- -- initialize display using above information
- -- receive buffer object which elements can be added to
- local text_display = gui.initializeDisplay(monitor_0)
- local debug_display = gui.initializeDisplay(monitor_5)
- setupDisplays(text_display, debug_display)
- while true do
- text_display:render()
- debug_display:render()
- gui.doEvents()
- end
- end
- function setupDisplays(text_display, debug_display)
- local w, h = debug_display.window:getSize()
- local debug_log = gui.Text:new {
- width = w,
- height = h,
- auto_scroll = true,
- }
- debug_display.window:addElement(debug_log)
- local text_container = gui.Element:new {
- x = 1,
- y = 1,
- width = 21,
- height = 12,
- bg_color = colors.gray,
- }
- text_display.window:addElement(text_container)
- local filler_text = gui.Text:new {
- x = 1,
- y = 1,
- width = 18,
- height = 10,
- bg_color = colors.white,
- text = "lorem ipsum dolor sit amet",
- text_color = colors.black,
- monitor_touch = function(self, e)
- debug_log:write(self.__name .. "\n")
- end,
- }
- text_container:addElement(filler_text)
- -- another way to attach the same callback function
- -- function filler_text:monitor_touch(e)
- -- debug_log:write(self.__name .. "\n")
- -- end
- local scroll_bar_container = gui.Element:new {
- x = 19,
- y = 1,
- width = 1,
- height = 10,
- bg_color = colors.lightGray,
- }
- text_container:addElement(scroll_bar_container)
- local scroll_up_button = gui.Element:new {
- x = 0,
- y = 0,
- width = 1,
- height = 1,
- bg_color = colors.red,
- monitor_touch = function(self, e)
- debug_log:write(self.__name .. "\n")
- filler_text.scroll_offset = filler_text.scroll_offset - 1
- end,
- }
- scroll_bar_container:addElement(scroll_up_button)
- local scroll_down_button = gui.Element:new {
- x = 0,
- y = 9,
- width = 1,
- height = 1,
- bg_color = colors.green,
- monitor_touch = function(self, e)
- debug_log:write(self.__name .. "\n")
- filler_text.scroll_offset = filler_text.scroll_offset + 1
- end,
- }
- scroll_bar_container:addElement(scroll_down_button)
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement