button
A simple button api with the option of drawing an image on the button.
| new(x, y, width, height, function [, image [, enabled]]) | Create a button, and add it to the internal table of buttons. |
|---|---|
| delete(id) | Remove a button from being clicked. |
| enable(id, enable) | Enable or disable a button. |
| exec(event [, drag [, monitor]]) | Takes an event in a table, checks if it's a mouse_click or mouse_drag, and sees if it's within a button, if so, execute its function. |
| drawButton(id) | Draw a button again, drawing its tDraw, or nothing if there is no image. |
| drawButtons() | Draw every button, this loops through the buttons table. |
| edit(id [, x [, y [, width [, height [, func [, image]]]]]]) | Edit a button, changing its function, position, or whatnot. |
| run(drag, touch) | Run buttons forever. |
- new(x, y, width, height, function [, image [, enabled]])Source
Create a button, and add it to the internal table of buttons.
Parameters
- x
numberX coordinate of the button. - y
numberY coordinate of the button. - width
numberWidth of the button. - height
numberHeight of the button. - function
functionThe function to run when the button is clicked. - image?
tableTable of blit lines to draw on the button. - enabled?
booleanWhether or not the button is active. Defaults to true.
Returns
stringid id of the button
Usage
local button = require("libs.button") local id = button.new(1,1,5,5,function() print("Hi!") end)
Create a button with an image
local button = require("libs.button") local image = { { "+-----+", "0000000", "fffffff", }, { "|Image|", "0000000", "fffffff", } { "+-----+", "0000000", "fffffff", }, } local id = button.new(1,1,7,3,function() print("Clicked!") end,image) -- Note the `image` parameter passed here.
- x
- delete(id)Source
Remove a button from being clicked.
Parameters
- id
stringbutton id to remove.
- id
- enable(id, enable)Source
Enable or disable a button.
Parameters
- id
stringButton to enable or disable. - enable
booleanWhether the button is enabled or not.
- id
- exec(event [, drag [, monitor]])Source
Takes an event in a table, checks if it's a
mouse_clickormouse_drag, and sees if it's within a button, if so, execute its function.Parameters
- event
tableEvent table to check formouse_clickormouse_drag. - drag?
booleanEnable button trigger on amouse_dragevent. Defaults to false. - monitor?
booleanEnable button trigger on amonitor_touchevent. Defaults to false.
- event
- drawButton(id)Source
Draw a button again, drawing its
tDraw, or nothing if there is no image.Parameters
- id
stringButton ID to draw image of.
- id
- drawButtons()Source
Draw every button, this loops through the buttons table.
- edit(id [, x [, y [, width [, height [, func [, image]]]]]])Source
Edit a button, changing its function, position, or whatnot.
Parameters
- id
stringID of the button to change. - x?
numberX coordinate of the button. - y?
numberY coordinate of the button. - width?
numberWidth of the button. - height?
numberHeight of the button. - func?
functionFunction to execute when the button is clicked. - image?
tableTable of blit lines to draw where the button is.
- id
- run(drag, touch)Source
Run buttons forever. Useful in parallel.
Parameters
- drag
booleanWhether or not dragging triggers buttons. - touch
booleanWhether or not monitor touches triggers buttons
Returns
functionA runnable function that runs buttons forever.
Usage
parallel.run(button.run(false,true))
- drag