Button Library Review

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
JJSax
Prole
Posts: 47
Joined: Fri Apr 04, 2014 3:59 am

Button Library Review

Post by JJSax »

Hi everyone, This looks a little longer than it is. About halfway down you'll see future stuff I plan in case it will help but it's not necessary to read. Just trying to save you some time.

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
Future stuff
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?
Attachments
button.love
(44.48 KiB) Downloaded 96 times
User avatar
CrimsonGuy
Prole
Posts: 48
Joined: Thu Apr 04, 2019 3:32 pm

Re: Button Library Review

Post by CrimsonGuy »

Hmm this post should be in the libraries and tools section, this subforum is more for asking questions about love2d and problems during development. Would be nice to have a github or bitbucket of the library to check and easily clone the code. The library seems nice, could be a good compliment to other guis available for Love2d.
JJSax
Prole
Posts: 47
Joined: Fri Apr 04, 2014 3:59 am

Re: Button Library Review

Post by JJSax »

CrimsonGuy wrote: Wed Jul 24, 2019 3:38 am Hmm this post should be in the libraries and tools section, this subforum is more for asking questions about love2d and problems during development. Would be nice to have a github or bitbucket of the library to check and easily clone the code. The library seems nice, could be a good compliment to other guis available for Love2d.
Thanks for the reply. I guess I didn't realize the libraries section was also for input on libraries. I was thinking it was more about already completed ones. Thanks for that info. And I do plan on making a github for it when it's more complete. When I do I'll now know to put it in the libraries section ;)
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 77 guests