Homebrew Project [Release] Handylib - A LUA / LOVE2D Library to handle GUI elements easily

tcsenpai

Member
OP
Newcomer
Joined
Feb 6, 2023
Messages
6
Trophies
0
Age
30
XP
35
Country
Italy

Here is the first working release of a project that I plan to expand a lot while I code homebrews for the 3DS (and incidentally, it works mostly also for the Switch too) :)

Handylib - by TheCookingSenpai (Version 0.1.0)​

GitHub Page

An handy library for Love2D that allows you to create and manage buttons and other GUI elements easily​

Install & Usage​

Just download handylib.lua and put it in your project directory. Then, you just need to:

local handy = require("handylib")

Requirements​

  • LUA (duh)
  • Love2D (duh x2)
  • Lovebrew (https://lovebrew.org/)
  • Some patience to learn the basics of love2d and lovebrew
  • Possibly a Nintendo 3DS

Buttons​

Methods​

  • addButton(name, text, x, y, size, image, callback)
  • removeButton(name)
  • checkButton(x, y)
  • buttonExists(name)
  • callButtonName(name)
  • callButtonIndex(index)

Logic​

A 400x240 navigation table is created, as well as a buttons table. The navigation table is used to check if a button exists at a certain position. The buttons table is used to store the button data.

The buttons have a name, a text (the one appearing in the GUI itself), an image and a callback function that is called when the button is pressed.

Every button occupies a certain area in the navigation table, based on the starting position and the size of the button. A 20x20 button at position 100,200 would occupy 20x20 cells in the navigation table starting from 100,200 to 120,220.

Using the classic Love2D callback functions, is possible to check if a button is pressed, clicked, hovered, released and so on.

Thanks to the cursor property it is also possible to navigate through the buttons using the dpad by increasing or decreasing the cursor value and using the callButtonIndex method. This is useful to enable a non-touch navigation system (or an hybrid one).

Example​

This snippet shows how to add a button to the GUI from any script that includes handylib.

local addButton = function (name, text, image, callback, x, y) if not handy:buttonExists(name) then local testButtonImage = love.graphics.newImage(Program.Attributes.AssetsFolder .. image) local size_x = testButtonImage:getWidth() local size_y = testButtonImage:getHeight() handy:addButton(name, text, x, y, {size_x, size_y}, testButtonImage, callback) local textPosition = {x + handy.buttons[name].size[1]/3, y + handy.buttons[name].size[2]/4} love.graphics.draw(handy.buttons[name].image, x, y) love.graphics.print(handy.buttons[name].text, textPosition[1], textPosition[2]) return true end return false end

Other GUI elements​

Work in progress.

License​

This library is released under the Creative Common BY-NC-SA license 4.0.

You can obtain a copy of the license at https://creativecommons.org/licenses/by-nc-sa/4.0/.
 

Attachments

  • handylib_repo.zip
    31.9 KB · Views: 29

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • BigOnYa @ BigOnYa:
    Is it a free to play bs, pay to get any good weapon/gear
  • K3Nv2 @ K3Nv2:
    Not free to play but $35
  • K3Nv2 @ K3Nv2:
    Inb4 kiiwii gives it a 0/10
  • BigOnYa @ BigOnYa:
    6/10 rating on steam
  • Psionic Roshambo @ Psionic Roshambo:
    I would like a Predator game "Kill Team" it takes place in the Jungle of the first movie, your team is sent to hunt the predator, using current tech drones and a trained team. Set traps use strategy to hunt and trap or kill the predator.
  • BigOnYa @ BigOnYa:
    Ill stick with my Battlefield. Yea a predator hunting game like that would be cool. Esp if you can be Arnold and say "Get to da choppa"
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    Maybe Arnold could do a cameo voice acting, he is the one briefing you on the mission
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    Honestly surprised they didn't make a tie in game for Predators that movie was awesome
  • Psionic Roshambo @ Psionic Roshambo:
    I was kinda sad the Yakuza guy died sword fighting a predator lol
  • Psionic Roshambo @ Psionic Roshambo:
    The Russian guy went out like a boss
  • Psionic Roshambo @ Psionic Roshambo:
    Double claymores to the face definitely kill a predator lol
  • BigOnYa @ BigOnYa:
    I went today and looked at a motorcycle someone was selling. I get there and the battery on it was dead, so the guy grabbed a battery charger and hooked it up. He plugged it into the wall, and the motorcycle sparked and started smoking. Come to find out the bike uses a 6 volt battery and the guy had the charger set to 12v. I said sorry to the dude and walked away. I felt bad for him tho.
  • Psionic Roshambo @ Psionic Roshambo:
    Sounds like it would be an exciting ride....
  • Psionic Roshambo @ Psionic Roshambo:
    Not sure I would want something on fire between my legs
  • BigOnYa @ BigOnYa:
    He ruined it basically. Sad cause it was a decent old bike. It would take more money to rewire the bike than it was worth tho.
  • Psionic Roshambo @ Psionic Roshambo:
    Yeah I'm sure at minimum the starter was fried
  • Psionic Roshambo @ Psionic Roshambo:
    Alternator and battery
  • BigOnYa @ BigOnYa:
    Prob alot of fried parts. It was still smoking when I left.
  • K3Nv2 @ K3Nv2:
    I would've said show me how it rides
  • Psionic Roshambo @ Psionic Roshambo:
    I always wanted one of those Smart Cars with a Hyabusa motor in it.
  • K3Nv2 @ K3Nv2:
    I'm getting sick and tired of cheap ass baking pans now
  • BigOnYa @ BigOnYa:
    I think it be cool to have one that would fit in my pickup truck bed, then I could put down ramps n drive it off.
    BigOnYa @ BigOnYa: I think it be cool to have one that would fit in my pickup truck bed, then I could put down...