Implementation
trubblegum edited this page Mar 27, 2012
·
7 revisions
Copy Gspot.lua into your project directory, and include the module in the usual way : gui = require('Gspot')
Gspot.lua returns an instance with a constructor. To create more instances use mainmenu = gui()
The following is a basic main.lua for use with LÖVE :
gui = require('Gspot') love.load = function() local button = gui:button('Hello', {128, 128, 128, 16}) button.click = function(this) print('Hello!') end end love.update = function(dt) gui:update(dt) end love.draw = function() gui:draw() end love.keypressed = function(key, code) gui:keypress(key, code) end love.mousepressed = function(x, y, button) gui:mousepress(x, y, button) end love.mousereleased = function(x, y, button) gui:mouserelease(x, y, button) end
The basic convention for constructing an element is :
Gspot:element(string label, nil or table or Gspot.pos pos, nil or Gspot.element parent)Some element constructors accept an additional parameter, as follows.
Gspot:element(string label, nil or table or Gspot.pos pos, nil or Gspot.element parent, variable value)The following exceptions adhere to convention, but accept different types as their 4rd (6th) parameter.
- image and imgbutton elements, which are constructed as follows.
Gspot:element(string label, nil or table or Gspot.pos pos, nil or Gspot.element parent, string path or love.image img)
- scrollbar elements, which are constructed as follows.
Gspot:element(string label, nil or table or Gspot.pos pos, nil or Gspot.element parent, nil or table or Gspot.scrollvalues values)
See Elements for a complete list of predefined element constructors.