This is my first time really diving into metatables. I wanted to make a button library that fits my needs better than what I've found so far (not to say the other ones I've found are bad). I would like to get a second opinion on it's development so far so I don't go too far off track, and fix issues earlier. Also should I make a native menu type button that has a drop down function or leave that to the user?
My goals for the library are to make it easy to use, functional, and easy on the computer and flexible.
I'm not so sure it's as easy as I'd like it to be, as the user has tons of functions to call to get it perfect, but I'm not sure the best way to solve it. See my main.lua. I did already make it possible to do things like set all the button states (selected, not selected, hovered, not hovered etc) with one function. Also anytime they want to update/draw a button they have to put it in the love.update/draw functions.
basic usage
Code: Select all
button = require("button")
function love.load()
button1 = button.newRectangleButton(20,20,100,100) -- creates a new button at x = 20, y = 20 and it's dimensions are 100/100
button1:setText("Button!", true) -- sets all button state text to "Button!"
button1:setColor({0.5,0.5,1,1}, true) -- sets the button main color for all states
-- button1:setImage(string imagePath[, bool allStates]) makes it so you can make your button an image instead
button1:setOutlineColor({1,0,0,1}, true) -- sets the outline color for all button states
button1:setOutlineWidth(3, true) -- sets button outline width for all states
button1:setHoverLineWidth(1) -- you can set them individually too
button1:setHoverSelectedOutlineWidth(1)
-- you have control over what happens when your cursor enters/exits the button, press/releases, hovers over, holds while pressing,
-- what buttons on the mouse or keyboard will trigger it
-- this will trigger when the cursor is released in the bounding box.
button1:setOnRelease(function()
print("Changing Background Color")
love.graphics.setBackgroundColor(
math.random(1,100)/100, math.random(1,100)/100, math.random(1,100)/100, math.random(1,100)/100
)
end)
-- this will happen when you cursor leaves the bounding box.
button1:setOnExit(function()
print("Exit")
end)
end
function love.update(dt)
button1:update() -- don't need to pass dt
end
function love.draw()
button1:draw()
end
I have future plans to add all the button types that you find in SUIT except maybe the odd shaped one (you'll know the one when you see it). I also plan on adding circle buttons as well.
SUIT: https://suit.readthedocs.io/en/latest/
Should I rework the variable format. Calling functions like button:setHoverSelectedOutlineColor(color) is hard to remember how to write out, and about half the time I call button:setSelectedHoverOutlineColor(color) to find an error since it's not a real function.
also, is there any way to make a spoiler section that will collapse a section like this so people have to click a button to see certain parts of a post?