diff --git a/main.lua b/main.lua index 8d1e34c..95136d0 100644 --- a/main.lua +++ b/main.lua @@ -1,8 +1,12 @@ local pop = require "pop" --TODO tell user that pop must be required with SLASHES 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()) + + --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 function love.draw() @@ -18,7 +22,13 @@ function love.mousereleased(button, x, y) end function love.keypressed(key) - if key == "escape" then - love.event.quit() + if not pop.keypressed(key, unicode) then + if key == "escape" then + love.event.quit() + end end end + +function love.keyreleased(key) + pop.keyreleased(key) +end diff --git a/pop/init.lua b/pop/init.lua index 41bf3e3..351881d 100644 --- a/pop/init.lua +++ b/pop/init.lua @@ -5,9 +5,15 @@ local pop = {} local path = ... --NOTE Pop.Box must be required as its directory name (w SLASHES)! -- elements are local ---TODO require these how skins are required local box = require(path .. ".elements.box") 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 pop.skins = {} @@ -22,6 +28,7 @@ pop.currentSkin = "clearspace" --default skin -- everything has one parent element (initialized at the end) pop.parentElement = false +-- this function actually creates elements based on what type of element is requested function pop.create(elementType, parent, ...) if not parent then parent = pop.parentElement @@ -29,6 +36,7 @@ function pop.create(elementType, parent, ...) local newElement + --TODO replace these with calls to pop.elements.ELEMENTNAME if elementType == "box" then newElement = box(pop, parent, ...) elseif elementType == "text" then @@ -44,6 +52,7 @@ end pop.box = function(...) return pop.create("box", ...) end pop.text = function(...) return pop.create("text", ...) end +-- called every frame to draw elements function pop.draw(element) if not element then element = pop.parentElement @@ -59,6 +68,7 @@ end -- 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.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) 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 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)