Giter VIP home page Giter VIP logo

handylib-for-lovebrew--and-love2d-'s Introduction

Handylib - by TheCookingSenpai

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/.

handylib-for-lovebrew--and-love2d-'s People

Contributors

thecookingsenpai avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.