forked from cyborgize/LoveFrames
-
Notifications
You must be signed in to change notification settings - Fork 15
(API) Button
Caldas Lopes edited this page Feb 4, 2021
·
5 revisions
The button object functions much like a button you would see in a modern day GUI.
function love.load()
loveframes = require("loveframes")
local button = loveframes.Create("button")
button:SetWidth(200)
button:SetText("Button")
button:Center()
button.OnClick = function(object, x, y)
object:SetText("You clicked the button!")
end
button.OnMouseEnter = function(object)
object:SetText("The mouse entered the button.")
end
button.OnMouseExit = function(object)
object:SetText("The mouse exited the button.")
end
end
function love.update(dt)
loveframes.update(dt)
end
function love.draw()
loveframes.draw()
end
function love.mousepressed(x, y, button)
loveframes.mousepressed(x, y, button)
end
function love.mousereleased(x, y, button)
loveframes.mousereleased(x, y, button)
end
Called every time the object is clicked
Arguments passed: self [object], mouse x [number], mouse y [number]
local button = loveframes.Create("button")
button.OnClick = function(object)
print("The button was clicked!")
end
Sets the object's text
object:SetText(text[string])
Gets the object's text
Returns 1 value: text [string]
local text = object:GetText()
Sets whether or not the object is clickable
object:SetClickable(clickable[bool])
Gets whether or not the object is clickable
Returns 1 value: clickable [boolean]
local clickable = object:GetClickable()
Sets whether or not the object is enabled
object:SetEnabled(enabled[bool])
Gets whether or not the object is enabled
Returns 1 value: enabled [bool]
local enabled = object:GetEnabled()
Sets the object's font
object:SetFont(font[font])
Gets the object's font
Returns 1 value: font [font]
local font = object:GetFont()
For an example of Button Group and Buttons with image (not Image Button) see https://github.com/linux-man/LoveFrames/blob/master/demo/examples/buttongroup.lua