computercraft monitor api -- The `drawButton` function draws a button at the specified position with the specified label text. -- It returns a table that contains the position and dimensions of the button. local monitor = peripheral.find("monitor") local buttons = {} function drawButton(x, y, label) buttons[label] = {} buttons[label].x1 = x buttons[label].y1 = y buttons[label].width = #label + 2 buttons[label].height = 3 computercraft monitor api How to get it for free? computercraft monitor api buttons[label].x2 = x + buttons[label].width - 1 buttons[label].y2 = y + buttons[label].height - 1 -- Draw the button frame and centered label monitor.setCursorPos(x, y) monitor.write("+" .. string.rep("-", buttons[label].width-2) .. "+") monitor.setCursorPos(x, y+1) monitor.write("|" .. centerText(label, buttons[label].width-2) .. "|") monitor.setCursorPos(x, y+2) monitor.write("+" .. string.rep("-", buttons[label].width-2) .. "+") computercraft monitor api How to get it? computercraft monitor api end -- The `centerText` function centers the specified text within the specified width. function centerText(text, width) local spacing = width - #text local leftSpacing = math.floor(spacing / 2) local rightSpacing = math.ceil(spacing / 2) return string.rep(" ", leftSpacing) .. text .. string.rep(" ", rightSpacing) end computercraft monitor api How to get it for free? computercraft monitor api -- The `processClick` function checks if the specified position is within any of the buttons -- and if so, calls the attached function. function processClick(x, y) for label, button in pairs(buttons) do if x >= button.x1 and x <= button.x2 and y >= button.y1 and y <= button.y2 then button.func() return end end computercraft monitor api How to use it? computercraft monitor api end -- The `attachFunction` function attaches the specified function to the specified button label. function attach(label, func) buttons[label].func = func end -- The `drawLabel` function draws a label at the specified position, centered within the specified width. function drawLabel(x, y, width, label) monitor.setCursorPos(x, y) computercraft monitor api How to dowload it? computercraft monitor api monitor.write(centerText(label, width)) end computercraft monitor api