btn1 = graphics.button:new()
Creates a new button named btn1.
Buttons come with the following values:
bkgColor - defines the background color of the button. Default value: colors.blue.
tColor - defines the color of the text. Default value: colors.white.
text - defines the text to be printed on the button. Default value: "Text".
w - defines the width of the button. Default value: 6.
h - defines the height of the button. Default value: 3.
textx - defines where the text will be on the X axis relatively to the button's X axis. Default value: 1.
texty - defines where the text will be on the Y axis relatively to the button's Y axis. Default value: 1.
x - defines where the button will be on the X axis. Default value: 2.
y - defines where the button will be on the Y axis. Default value: 2.
trigger - defines the function that will run when the button is triggered. (If you want to handle that yourself with your own code, no worries, you can do that. The detect function will return true if the button is clicked.) Default value: function()
print("Default trigger function.
")
end
Now with all the values covered, let's go to the 2 functions!
btn1:draw() draws the button just as its name says.
btn1:detect(x, y, trig) takes the received X and Y values and uses them to find out if the button is clicked or not, then if it is, if trig is set to true, it will trigger the button, thus running the trigger function mentioned before. Most useful when paired with the mouse_click event.
That's about it so far. Will work on adding more functions (primarily drawCentered and drawCornered!)