viewportAPI.new({})returns a new viewport. parameters are provided as a table:termthe terminal which will be managed by the new viewport - requiredtextColorthe default text color - defaults to whitebackgroundColorthe default background color - defaults to black
viewport:move(x, y)moves the panel behin the viewport.viewport:setPosition(x, y)set the panels position, i.e. an absolute movementviewport:addElement(element)adds an element, e.g. a button created by the buttonAPI (docs)viewport:removeElement(element)removes an element from a viewportviewport:handleClick(xPos, yPos)calls the callback function of every element at the given positionviewport:redraw()redraws all element on this viewport
An element has to have:
x,y,width,heightas either a number or a function which takes 2 arguments: the terms height and width and returns a number. e.g.function x(self, termx, termy) return termx / 2 end
An element can have:
draw(term, offsetX, offsetY)a function which draws the button on the given terminal in respect to the backpanel offsetisStickya boolean (if it is missing it counts as false). True if the element is on the viewport, false if it's on the backpanel.callback(element, xPos, yPos)a function which will be called if the button occupies the clicked coordinates.elementis the element itself, _Pos are the clicked coordinates. Should returntrueif a redraw after its call is needed.
viewport = viewportAPI.new(term)
viewport:addElement(someButton)
viewport:redraw()