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 number X coordinate of the button.
- y number Y coordinate of the button.
- width number Width of the button.
- height number Height of the button.
- function function The function to run when the button is clicked.
- image? table Table of blit lines to draw on the button.
- enabled? boolean Whether or not the button is active. Defaults to true.
Returns
- string id 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.
- delete(id)Source
Remove a button from being clicked.
Parameters
- id string button id to remove.
- enable(id, enable)Source
Enable or disable a button.
Parameters
- id string Button to enable or disable.
- enable boolean Whether the button is enabled or not.
- exec(event [, drag [, monitor]])Source
Takes an event in a table, checks if it's a
mouse_click
ormouse_drag
, and sees if it's within a button, if so, execute its function.Parameters
- event table Event table to check for
mouse_click
ormouse_drag
. - drag? boolean Enable button trigger on a
mouse_drag
event. Defaults to false. - monitor? boolean Enable button trigger on a
monitor_touch
event. Defaults to false.
- event table Event table to check for
- drawButton(id)Source
Draw a button again, drawing its
tDraw
, or nothing if there is no image.Parameters
- id string Button ID to draw image of.
- 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 string ID of the button to change.
- x? number X coordinate of the button.
- y? number Y coordinate of the button.
- width? number Width of the button.
- height? number Height of the button.
- func? function Function to execute when the button is clicked.
- image? table Table of blit lines to draw where the button is.
- run(drag, touch)Source
Run buttons forever. Useful in parallel.
Parameters
- drag boolean Whether or not dragging triggers buttons.
- touch boolean Whether or not monitor touches triggers buttons
Returns
- function A runnable function that runs buttons forever.
Usage
parallel.run(button.run(false,true))