Checkbox part of the API:
checkbox = { text = "Check Box", x = 2, y = 2, checked = false, w = 0, h = 0, new = function(self) local new = {} setmetatable(new, {__index = self}) return new end, draw = function(self) local oldBkgColor = term.getBackgroundColor() local text = self.text local x = self.x local y = self.y term.setCursorPos(x, y) if self.checked == false then term.setBackgroundColor(colors.gray) term.write(" ") else term.setBackgroundColor(colors.blue) term.write(" ") end term.setBackgroundColor(oldBkgColor) term.write(" ") term.write(text) w = 2 + string.len(text) h = 1 end, detect = function(self, x, y) if x >= self.x and x <= (self.x + self.w) and y >= self.y and y <= (self.y + self.h) then if checked == false then checked = true self:draw() else checked = false self:draw() end end end }
Checkbox program:
term.clear() term.setCursorPos(1, 1) os.loadAPI("DoorOS/apis/graphics") checkbox = graphics.checkbox:new() checkbox.x = 2 checkbox.y = 2 checkbox.text = "I have read the EULA and accept it." checkbox:draw() while true do local event, btn, x, y = os.pullEvent("mouse_click") checkbox:detect(x, y) end
Any help is appreciated!