Skip to content

steveRoll-git/zap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 

Repository files navigation

Zap

Zap is a minimal UI framework made for LÖVE, heavily inspired by the other prominent UI frameworks - Helium and Inky.
(It doesn't use any love-specific features, so you could use it in other Lua frameworks if you wish.)

Usage

  1. Require the library.
local zap = require "zap"
  1. Define element classes.
local button = zap.elementClass()

function button:init()
  self.count = 0
end

function button:mouseClicked(btn)
  if btn == 1 then
    self.count = self.count + 1
  end
end

function button:render(x, y, w, h)
  love.graphics.setColor(1, 1, 1)
  love.graphics.rectangle("fill", x, y, w, h)
  love.graphics.setColor(0, 0, 0)
  love.graphics.printf("I've been clicked " .. self.count .. " times!", x, y, w, "center")
end
  1. Create instances of elements by calling the element class.
local button1 = button()
local button2 = button()
  1. Create a Scene and hook it to the necessary callbacks.
local scene = zap.createScene()

function love.mousemoved(x, y, dx, dy)
  scene:moveMouse(x, y, dx, dy)
end

function love.mousepressed(x, y, btn)
  scene:pressMouse(btn)
end

function love.mousereleased(x, y, btn)
  scene:releaseMouse(btn)
end
  1. Render elements in your draw callback.
function love.draw()
  scene:begin()

  button1:render(100, 100, 200, 16)
  button2:render(100, 200, 200, 16)

  scene:finish()
end

And that's the gist of it!

You can render elements from within other elements, so structure your UI however you see fit.

Extra

Out of the box, Zap provides mouse movement, press and release events. If you want to add more events on top, such as mousewheel movement, use Scene:raiseMouseEvent:

function love.wheelmoved(x, y)
  scene:raiseMouseEvent("wheelMoved", x, y)
end

About

A small UI framework written in Lua.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages