more wips

This commit is contained in:
Paul Liverman III 2015-11-20 16:41:11 -08:00
parent 723997fe7a
commit 2bc9152514
2 changed files with 32 additions and 4 deletions

View File

@ -1,8 +1,12 @@
local pop = require "pop" --TODO tell user that pop must be required with SLASHES local pop = require "pop" --TODO tell user that pop must be required with SLASHES
function love.load() function love.load()
pop.box() -- returns the box element local box = pop.box() -- returns the box element
-- or pop.create("box") (this is what is actually called when you call pop.box()) -- or pop.create("box") (this is what is actually called when you call pop.box())
--TODO uncomment these once text is implemented!
--local text = pop.text(box) -- box will become the parent element of text
--text:setText("Hello and welcome to an example of Pop.Box, a very small shitty example.")
end end
function love.draw() function love.draw()
@ -18,7 +22,13 @@ function love.mousereleased(button, x, y)
end end
function love.keypressed(key) function love.keypressed(key)
if not pop.keypressed(key, unicode) then
if key == "escape" then if key == "escape" then
love.event.quit() love.event.quit()
end end
end end
end
function love.keyreleased(key)
pop.keyreleased(key)
end

View File

@ -5,9 +5,15 @@ local pop = {}
local path = ... --NOTE Pop.Box must be required as its directory name (w SLASHES)! local path = ... --NOTE Pop.Box must be required as its directory name (w SLASHES)!
-- elements are local -- elements are local
--TODO require these how skins are required
local box = require(path .. ".elements.box") local box = require(path .. ".elements.box")
local text = require(path .. ".elements.text") local text = require(path .. ".elements.text")
--TODO require these how skins are required
pop.elements = {}
local elements = lf.getDirectoryItems(path .. "/elements") --NOTE Pop.Box must be required with SLASHES!
for _, v in ipairs(elements) do
local name = v:sub(1,-5)
pop.elements[name] = require(path .. "/elements/" .. name) --TODO test this actually works right
end
-- skins define how elements are drawn -- skins define how elements are drawn
pop.skins = {} pop.skins = {}
@ -22,6 +28,7 @@ pop.currentSkin = "clearspace" --default skin
-- everything has one parent element (initialized at the end) -- everything has one parent element (initialized at the end)
pop.parentElement = false pop.parentElement = false
-- this function actually creates elements based on what type of element is requested
function pop.create(elementType, parent, ...) function pop.create(elementType, parent, ...)
if not parent then if not parent then
parent = pop.parentElement parent = pop.parentElement
@ -29,6 +36,7 @@ function pop.create(elementType, parent, ...)
local newElement local newElement
--TODO replace these with calls to pop.elements.ELEMENTNAME
if elementType == "box" then if elementType == "box" then
newElement = box(pop, parent, ...) newElement = box(pop, parent, ...)
elseif elementType == "text" then elseif elementType == "text" then
@ -44,6 +52,7 @@ end
pop.box = function(...) return pop.create("box", ...) end pop.box = function(...) return pop.create("box", ...) end
pop.text = function(...) return pop.create("text", ...) end pop.text = function(...) return pop.create("text", ...) end
-- called every frame to draw elements
function pop.draw(element) function pop.draw(element)
if not element then if not element then
element = pop.parentElement element = pop.parentElement
@ -59,6 +68,7 @@ end
-- TODO decide if we should track mouse movement -- TODO decide if we should track mouse movement
-- these are functions to be overwritten by user if they want a global event handler
function pop.onMousePress(button, x, y) end function pop.onMousePress(button, x, y) end
function pop.onMouseRelease(button, x, y) end function pop.onMouseRelease(button, x, y) end
@ -72,6 +82,14 @@ function pop.mousereleased(button, x, y)
-- if it does, use that, else, use the global callback (defined above..as nil) -- if it does, use that, else, use the global callback (defined above..as nil)
end end
function pop.keypressed(key, unicode)
--TODO handle this in some manner when needed
end
function pop.keyreleased(key)
--TODO handle this when needed
end
-- initialize the top element -- initialize the top element
pop.parentElement = box(pop, {child={}}) -- dummy object because it has no parent pop.parentElement = box(pop, {child={}}) -- dummy object because it has no parent
--pop.parentElement:setSizeControl("specified") -- make it not try to update itself (TODO or based on outro, and custom code to check top parent against screen size) --pop.parentElement:setSizeControl("specified") -- make it not try to update itself (TODO or based on outro, and custom code to check top parent against screen size)