Skip to content

ButtonLib

Thomas2889 edited this page Aug 15, 2021 · 1 revision

Quick Setup:

local Bl = require("ButtonLib")
local gpu = require("component").gpu

-- Call setup before anything else
Bl.Setup()

local running = true
local function OnButton(x, y)
    print("You clicked the screen at "..tostring(x)..", "..tostring(y))
    running = false
end

local w, h = gpu.getResolution()
-- This adds a button to the entire screen which, when clicked, runs the callback OnButton
Bl.AddButton("BigButton", 1, 1, w, h, OnButton)

while running do
    require("os").sleep(0.05)
end

-- Call shutdown to un-register buttons (otherwise they'll still be clickable once the program exits!)
Bl.Shutdown()

All Functions:

  • Setup() Should be called before anything else
  • Shutdown() This will shut the library down to make sure buttons cant be clicked once the program exits
  • AddButton(name, x1, y1, x2, y2, callback, button = both, priority = 0) This will add a button in the given region. Note default button choice is both, meaning it'll respond to left and right.
  • RemoveButton(name) This will attempt to remove a button of the given name

Clone this wiki locally