Posted 06 September 2015 - 06:21 AM
RedButton
What is Redbutton?
redbutton is a simple and easy way to create buttons on computercraft
all click event handling done in the API no need to make your own calculations!
How do i use Redbutton?
Spoiler
1. Creating buttons
-- Welcome to Redbutton, lets start by creating our first button!
-- first, we need to load the api
os.loadAPI("redbutton")
-- now lets add our button and draw it to the screen
local mybutton = redbutton.addButton(
5,5,15,2,colors.white,colors.blue,"My Button XD")
-- add button takes the arguments (startx, starty,
-- width, height, textcolor, backcolor, text)
-- now to draw it
mybutton:draw()
-- and your all done XD
2. Handling events
-- now to handle our button clicks!
os.loadAPI("redbutton")
local button = redbutton.addButton(
5,5,15,2,colors.white,colors.blue,"Click Me!")
-- now for a while loop for checking click events
while true do
-- ok now lets check if our button is pressed
ev = {os.pullEvent()} -- make sure your event is in a table
-- now to pass our event table onto our button
if(redbutton:pressed(ev))then
-- exit the program if our button was pressed
break
end
end
3. Changing colors
-- to change colors just call this method from the button --
mybutton:colorize(textcolor, backcolor)
4. Editing position
-- to change position just call this method from the button --
mybutton:setPos(x,y,clear previous position with color)
5. clearing a button
-- to clear a button use -
mybutton:clear(clear with color)
6. renaming a button
-- to rename a button use -
mybutton:rename(newname)
Download : http://pastebin.com/uks1ZeP2
Edited on 07 September 2015 - 12:51 PM