diff --git a/.gitignore b/.gitignore index bc78f0a..dd31a1b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ lua51.dll moon*.exe moonscript.dll +spec/*.lua diff --git a/config.ld b/config.ld index 6bd76c4..71d505d 100644 --- a/config.ld +++ b/config.ld @@ -1,11 +1,11 @@ file = { "init.moon", - "main.moon", + --"main.moon", "util.moon", } project = "Pop.Box()" -description = "GUI library for [LOVE](https://love2d.org/), designed for ease of use" +description = "GUI library for [LÖVE](https://love2d.org/), designed for ease of use" title = "Documentation" --package = "pop" --has to be same name as source directory format = "markdown" diff --git a/docs/index.html b/docs/index.html index e915515..a3a3e90 100644 --- a/docs/index.html +++ b/docs/index.html @@ -32,7 +32,6 @@

Modules

@@ -41,7 +40,7 @@
-

GUI library for LOVE, designed for ease of use

+

GUI library for LÖVE, designed for ease of use

Modules

@@ -49,10 +48,6 @@ - - - - @@ -63,7 +58,7 @@
generated by LDoc 1.4.3 -Last updated 2016-08-02 16:30:36 +Last updated 2016-08-20 21:29:17
diff --git a/docs/modules/main.html b/docs/modules/main.html index 714655c..9090cec 100644 --- a/docs/modules/main.html +++ b/docs/modules/main.html @@ -30,10 +30,6 @@
  • Index
  • -

    Contents

    -

    Modules

    @@ -59,47 +55,18 @@ -

    Functions

    -
    pop The Pop.Box GUI itself.
    mainA demo program for Pop.Box.
    util Utility functions, intended for internal use only.
    - - - - -
    pop () - -


    -

    Functions

    - -
    -
    - - pop () -
    -
    - - - - - - - - - - -
    -
    generated by LDoc 1.4.3 -Last updated 2016-08-02 16:30:36 +Last updated 2016-08-20 19:46:37
    diff --git a/docs/modules/pop.html b/docs/modules/pop.html index 0c8fb2b..87cc2d7 100644 --- a/docs/modules/pop.html +++ b/docs/modules/pop.html @@ -34,14 +34,12 @@

    Modules

    @@ -69,7 +67,7 @@ Loads elements, skins, extensions, and initializes pop.screen. - create (element, parent) + create (element, parent, ...) Creates an element. @@ -126,27 +124,6 @@ -

    Issues

    - - - - - - - - - - - - - -
    load-todo1Determine if extensions should have a reference saved (and the possibility of a load function?) - require into pop.extensions by filename
    mousemoved-todo2Implement a way for an element to attach itself to love.mousemoved() events?
    mousereleased-todo3 Figure out how to bring a focused element to the front of view (aka the first element in its parent's children). - (If I do it right here, the for loop above may break! I need to test/figure this out.) -NOTE this might cause an error in the above for loop! - basically, move focused element to front of its parent's child -element.parent\focusChild element -table.insert element.parent, element.parent\removeChild(element),


    @@ -160,7 +137,9 @@ table.insert element.parent, element.parent\removeChild(element), load ()
    - Loads elements, skins, extensions, and initializes pop.screen. IMPORTANT: Intended to only be called once, and is automatically called when you require Pop.Box. + Loads elements, skins, extensions, and initializes pop.screen.

    + +

    IMPORTANT: Intended to only be called once, and is automatically called when you require Pop.Box. @@ -175,7 +154,7 @@ table.insert element.parent, element.parent\removeChild(element),

    - create (element, parent) + create (element, parent, ...)
    Creates an element. @@ -187,8 +166,12 @@ table.insert element.parent, element.parent\removeChild(element), A string naming the element class to use.
  • parent - Optional The parent element. If false, an element is created with no parent. If nil, defaults to pop.screen. - (Note: An element with no parent will not be handled by Pop.Box's event handlers unless you handle it explicitly.) + [opt] The parent element. If false, an element is created with no parent. If nil, defaults to pop.screen. +
  • +
  • ... + [opt] Any number of parameters can be passed to the constructor for the element.

    + +

    (Note: An element with no parent will not be handled by Pop.Box's event handlers unless you handle it explicitly.)

  • @@ -215,7 +198,7 @@ table.insert element.parent, element.parent\removeChild(element), The amount of time passed since the last call to update, in seconds.
  • element - Optional The element to update. Defaults to pop.screen (and loops through all its children). + [opt] The element to update (will update all its children as well). Defaults to pop.screen.
  • @@ -235,7 +218,7 @@ table.insert element.parent, element.parent\removeChild(element),

    Parameters:

    @@ -298,7 +281,7 @@ table.insert element.parent, element.parent\removeChild(element), The mouse button pressed.
  • element - Optional The element to check for event handling. Defaults to pop.screen (and loops through all its children). + [opt] The element to check for event handling (will check its children as well). Defaults to pop.screen.
  • @@ -332,7 +315,7 @@ table.insert element.parent, element.parent\removeChild(element), The mouse button released.
  • element - Optional The element to check for event handling. Defaults to pop.screen (and loops through all its children). + [opt] The element to check for event handling (will check its children as well). Defaults to pop.screen.
  • @@ -428,19 +411,19 @@ table.insert element.parent, element.parent\removeChild(element), skin (element, skin, depth)
    - Applies skins to elements. (*NOTE^: This function will be rewritten and change at some point...) + Applies skins to elements. (NOTE: This function will be rewritten and change at some point...)

    Parameters:

    @@ -460,7 +443,7 @@ table.insert element.parent, element.parent\removeChild(element),

    Parameters:

    @@ -480,7 +463,7 @@ table.insert element.parent, element.parent\removeChild(element),

    Parameters:

    @@ -511,11 +494,14 @@ table.insert element.parent, element.parent\removeChild(element),
  • skins All skins are stored here.
  • +
  • extensions + All extensions are loaded here. +
  • screen The top level GUI element. Represents the game screen. Initialized in pop.load()
  • focused - The currently focused GUI element (or false if none is focused). + The currently focused GUI element (or false if none is focused).
  • @@ -527,58 +513,6 @@ table.insert element.parent, element.parent\removeChild(element), -
    - -

    Issues

    - -
    -
    - - load-todo1 -
    -
    - Determine if extensions should have a reference saved (and the possibility of a load function?) - require into pop.extensions by filename - - - - - - - -
    -
    - - mousemoved-todo2 -
    -
    - Implement a way for an element to attach itself to love.mousemoved() events? - - - - - - - -
    -
    - - mousereleased-todo3 -
    -
    - Figure out how to bring a focused element to the front of view (aka the first element in its parent's children). - (If I do it right here, the for loop above may break! I need to test/figure this out.) -NOTE this might cause an error in the above for loop! - basically, move focused element to front of its parent's child -element.parent\focusChild element -table.insert element.parent, element.parent\removeChild(element), - - - - - - -
    @@ -587,7 +521,7 @@ table.insert element.parent, element.parent\removeChild(element),
    generated by LDoc 1.4.3 -Last updated 2016-08-02 16:30:36 +Last updated 2016-08-20 21:29:17
    diff --git a/docs/modules/util.html b/docs/modules/util.html index 5f3d3b1..b9215b8 100644 --- a/docs/modules/util.html +++ b/docs/modules/util.html @@ -39,7 +39,6 @@

    Modules

    @@ -55,7 +54,7 @@

    Info:

    @@ -113,7 +112,7 @@
    generated by LDoc 1.4.3 -Last updated 2016-08-02 16:30:36 +Last updated 2016-08-20 21:29:17
    diff --git a/elements/element.lua b/elements/element.lua new file mode 100644 index 0000000..5a14e82 --- /dev/null +++ b/elements/element.lua @@ -0,0 +1,23 @@ +local element +do + local _class_0 + local _base_0 = { + setSize = function(self) end + } + _base_0.__index = _base_0 + _class_0 = setmetatable({ + __init = function(self) end, + __base = _base_0, + __name = "element" + }, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({}, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end + }) + _base_0.__class = _class_0 + element = _class_0 + return _class_0 +end diff --git a/elements/element.moon b/elements/element.moon new file mode 100644 index 0000000..bc18de5 --- /dev/null +++ b/elements/element.moon @@ -0,0 +1,12 @@ +--- A generic element every element must inherit from. +--- @module pop +--- @copyright Paul Liverman III (2016) +--- @license The MIT License (MIT) +--- @release 0.0.0 + +class element + new: => + --do stuff + + setSize: => + --do more stuff! diff --git a/init.lua b/init.lua index 1e2f50b..e0df5aa 100644 --- a/init.lua +++ b/init.lua @@ -8,10 +8,13 @@ local pop = { if not (love.getVersion) then error("Pop.Box only supports LOVE versions >= 0.9.1") end -if (...):sub(-4) == "init" then - error("Pop.Box must be required by its containing folder") -end local path = ... +if (...):sub(-4) == "init" then + path = (...):sub(1, -5) + if not (path) then + path = "." + end +end local filesystem, graphics do local _obj_0 = love @@ -23,6 +26,7 @@ local inheritsFromElement inheritsFromElement = require(tostring(path) .. "/util").inheritsFromElement pop.elements = { } pop.skins = { } +pop.extensions = { } pop.screen = false pop.focused = false pop.load = function() @@ -85,7 +89,10 @@ pop.load = function() break end local name = extensions[i]:sub(1, -5) - require(tostring(path) .. "/extensions/" .. tostring(name)) + pop.extensions[name] = require(tostring(path) .. "/extensions/" .. tostring(name)) + if pop.extensions[name].load then + pop.extensions[name].load(pop) + end print("extension loaded: \"" .. tostring(name) .. "\"") _continue_0 = true until true @@ -249,7 +256,7 @@ pop.skin = function(element, skin, depth) end else for i = 1, #element.child do - pop.skin(element.child[i], skin, false) + pop.skin(element.child[i], skin, true) end end end diff --git a/init.moon b/init.moon index 51a857e..c6d4806 100644 --- a/init.moon +++ b/init.moon @@ -15,11 +15,13 @@ pop = { unless love.getVersion error "Pop.Box only supports LOVE versions >= 0.9.1" -if (...)\sub(-4) == "init" - error "Pop.Box must be required by its containing folder" - path = ... +if (...)\sub(-4) == "init" + path = (...)\sub 1, -5 + unless path + path = "." + import filesystem, graphics from love import insert from table import inheritsFromElement from require "#{path}/util" @@ -27,25 +29,29 @@ import inheritsFromElement from require "#{path}/util" --- @table pop --- @field elements All GUI classes are stored here. --- @field skins All skins are stored here. +--- @field extensions All extensions are loaded here. --- @field screen The top level GUI element. Represents the game screen. Initialized in `pop.load()` --- @see pop.load ---- @field focused The currently focused GUI element (or false if none is focused). +--- @field focused The currently focused GUI element (or `false` if none is focused). pop.elements = {} pop.skins = {} +pop.extensions = {} pop.screen = false pop.focused = false ---- Loads elements, skins, extensions, and initializes `pop.screen`. **IMPORTANT**: Intended to only be called once, and is automatically called when you require Pop.Box. +--- Loads elements, skins, extensions, and initializes `pop.screen`. +--- +--- **IMPORTANT**: Intended to only be called once, and is automatically called when you require Pop.Box. --- @function load --- @see pop ---- @todo @see Elements ---- @todo @see Skins ---- @todo @see Extensions pop.load = -> + --@todo @ see Elements + --@todo @ see Skins + --@todo @ see Extensions elements = filesystem.getDirectoryItems "#{path}/elements" for i = 1, #elements -- ignore non-Lua files @@ -96,10 +102,13 @@ pop.load = -> unless extensions[i]\sub(-4) == ".lua" continue - --- @todo Determine if extensions should have a reference saved (and the possibility of a load function?) -- require into pop.extensions by filename name = extensions[i]\sub 1, -5 - require "#{path}/extensions/#{name}" + pop.extensions[name] = require "#{path}/extensions/#{name}" + + -- call the extension's load function if it exists + if pop.extensions[name].load + pop.extensions[name].load pop print "extension loaded: \"#{name}\"" @@ -113,12 +122,14 @@ pop.load = -> --- Creates an element. --- @function create --- @param element A string naming the element class to use. ---- @param parent *Optional* The parent element. If `false`, an element is created with no parent. If `nil`, defaults to `pop.screen`. +--- @param parent[opt] The parent element. If `false`, an element is created with no parent. If `nil`, defaults to `pop.screen`. +--- @param ...[opt] Any number of parameters can be passed to the constructor for the element. +--- --- (**Note**: An element with no parent will not be handled by Pop.Box's event handlers unless you handle it explicitly.) --- @see pop ---- @todo @see Elements pop.create = (element, parent=pop.screen, ...) -> + --@todo @ see Elements -- if valid parent element, use it if inheritsFromElement parent element = pop.elements[element](parent, ...) @@ -140,10 +151,10 @@ pop.create = (element, parent=pop.screen, ...) -> --- Event handler for `love.update()`. --- @function update --- @param dt The amount of time passed since the last call to update, in seconds. ---- @param element *Optional* The element to update. Defaults to `pop.screen` (and loops through all its children). ---- @todo Define Elements and @see that documentation from here. Generic documentation, not specifically element! +--- @param element[opt] The element to update (will update all its children as well). Defaults to `pop.screen`. pop.update = (dt, element=pop.screen) -> + --@todo Define Elements and @ see that documentation from here. Generic documentation, not specifically element! -- data.update boolean controls an element and its children being updated if element.data.update if element.update @@ -155,10 +166,10 @@ pop.update = (dt, element=pop.screen) -> --- Event handler for `love.draw()`. --- @function draw ---- @param element *Optional* The element to draw. Defaults to `pop.screen` (and loops through all its children). ---- @todo @see Elements +--- @param element[opt] The element to draw (will draw all its children as well). Defaults to `pop.screen`. pop.draw = (element=pop.screen) -> + --@todo @ see Elements -- data.draw boolean controls an element and its children being drawn if element.data.draw if element.draw @@ -176,8 +187,8 @@ pop.draw = (element=pop.screen) -> --- @param dy The distance on the y axis the mouse was moved. --- @return `true` / `false`: Was the event handled? ---- @todo Implement a way for an element to attach itself to `love.mousemoved()` events? pop.mousemoved = (x, y, dx, dy) -> + --@todo Implement a way for an element to attach itself to `love.mousemoved()` events? if pop.focused and pop.focused.mousemoved return pop.focused\mousemoved x, y, dx, dy @@ -190,7 +201,7 @@ pop.mousemoved = (x, y, dx, dy) -> --- @param x The x coordinate of the mouse press. --- @param y The y coordinate of the mouse press. --- @param button The mouse button pressed. ---- @param element *Optional* The element to check for event handling. Defaults to `pop.screen` (and loops through all its children). +--- @param element[opt] The element to check for event handling (will check its children as well). Defaults to `pop.screen`. --- @return `true` / `false`: Was the event handled? pop.mousepressed = (x, y, button, element) -> @@ -226,7 +237,7 @@ pop.mousepressed = (x, y, button, element) -> --- @param x The x coordinate of the mouse release. --- @param y The y coordinate of the mouse release. --- @param button The mouse button released. ---- @param element *Optional* The element to check for event handling. Defaults to `pop.screen` (and loops through all its children). +--- @param element[opt] The element to check for event handling (will check its children as well). Defaults to `pop.screen`. --- @return `true` / `false`: Was a click handled? --- @return `true` / `false`: Was a mouse release handled? @@ -255,7 +266,7 @@ pop.mousereleased = (x, y, button, element) -> -- if we clicked, we're focused! if clickedHandled pop.focused = element - --- @todo Figure out how to bring a focused element to the front of view (aka the first element in its parent's children). + --@todo Figure out how to bring a focused element to the front of view (aka the first element in its parent's children). --- (If I do it right here, the for loop above may break! I need to test/figure this out.) --NOTE this might cause an error in the above for loop! -- basically, move focused element to front of its parent's child @@ -322,12 +333,11 @@ pop.textinput = (text) -> ---- Applies skins to elements. (**NOTE^*: This function will be rewritten and change at some point...) +--- Applies skins to elements. (**NOTE**: This function will be rewritten and change at some point...) --- @function skin ---- @param element The element to skin. Defaults to `pop.screen` (and loops through all its children). ---- @param skin The skin to use, can be a string or an actual skin object, defaults to a default skin that is part of Pop.Box. ---- @param depth Can be an integer for how many levels to go skinning. Alternately, if `true`, will skin all children. ---- @todo Rewrite the skin function taking advantage of data block / whatever else is needed. +--- @param element The element to skin (will also be applied to children). Defaults to `pop.screen`. +--- @param skin The skin to use, can be a string or an actual skin object, defaults to the default skin included with Pop.Box. +--- @param depth[opt] An integer for how many child levels to skin, OR, if `true`, will skin all children. --TODO rewrite skin system to not rely on knowing internals of elements, -- instead call functions like setColor and setBackground @@ -335,6 +345,7 @@ pop.textinput = (text) -> -- depth can be an integer for how many levels to go down when skinning -- defaults to pop.screen and the default skin pop.skin = (element=pop.screen, skin=pop.skins.default, depth) -> + --@todo Rewrite the skin function taking advantage of data block / whatever else is needed. if element.background and skin.background element.background = skin.background if element.color and skin.color @@ -348,16 +359,16 @@ pop.skin = (element=pop.screen, skin=pop.skins.default, depth) -> pop.skin element.child[i], skin, depth - 1 else for i = 1, #element.child - pop.skin element.child[i], skin, false + pop.skin element.child[i], skin, true --- Draws simple rectangle outlines to debug placement of elements. --- @function debugDraw ---- @param element The element to draw. Defaults to `pop.screen` (and loops through all its children). ---- @todo Make this better in the future when different element types have been created and whatnot. +--- @param element The element to draw (will draw its children as well). Defaults to `pop.screen`. pop.debugDraw = (element=pop.screen) -> + --@todo Make this better in the future when different element types have been created and whatnot. if element.debugDraw element\debugDraw! else @@ -376,10 +387,10 @@ pop.debugDraw = (element=pop.screen) -> --- Prints a basic structure of GUI elements with minimal info. --- @function printElementTree ---- @param element The element to start at. Defaults to `pop.screen` (and loops through all its children). ---- @todo Correct this once elements are reimplemented if it needs correction. +--- @param element The element to start at. Defaults to `pop.screen`. pop.printElementTree = (element=pop.screen, depth=0) -> + --@todo Correct this once elements are reimplemented if it needs correction. cls = element.__class.__name if cls == "text" diff --git a/main.lua b/main.lua index 0956661..2256a5c 100644 --- a/main.lua +++ b/main.lua @@ -1,2 +1,2 @@ -local pop = require("init") +local pop = require("") return print(pop, pop.elements) diff --git a/main.moon b/main.moon index dabb10c..c223478 100644 --- a/main.moon +++ b/main.moon @@ -2,8 +2,7 @@ --- @copyright Paul Liverman III (2016) --- @license The MIT License (MIT) +pop = require "" --- @todo write this! -pop = require "init" - -print(pop, pop.elements) +print(pop, pop.elements) --NOTE TEMPORARY diff --git a/spec/love.moon b/spec/love.moon new file mode 100644 index 0000000..5d66664 --- /dev/null +++ b/spec/love.moon @@ -0,0 +1,22 @@ +lfs = require "lfs" + +return { + getVersion: -> + 0, 10, 1, "Super Toast" + filesystem: + getDirectoryItems: (path) -> + ok, results = pcall -> + results = {} + for file in lfs.dir lfs.currentdir! .. "/" .. path + table.insert results, file + return results + if ok + return results + else + return {} + graphics: + getWidth: -> + return 1280 + getHeight: -> + return 720 +} diff --git a/spec/pop_spec.moon b/spec/pop_spec.moon new file mode 100644 index 0000000..be3a4bf --- /dev/null +++ b/spec/pop_spec.moon @@ -0,0 +1,75 @@ +lfs = require "lfs" + +expose "fake LOVE 0.10.1", -> + + _G.love = require "spec/love" + +describe "Pop.Box", -> + + --it "errors when require'd wrong", -> + -- assert.error -> require "init" + + it "can be required by 'init'", -> + assert.has_no.errors -> require "init" + + pending "errors if you use LOVE < 0.9.1", -> + + describe "pop.load", -> + + pending "loads all elements", -> + -- check they are in elements[name] + -- check specifics if able have used their load functions + -- if able, check that custom wraps have been called + + pending "loads all skins", -> + -- see checks for loading all elements + + pending "loads all extensions", -> + -- see checks for loading all elements + + pending "creates an element the size of the game window", -> + -- use our shim's width/height, check the size of the element, check that it actually is an element class object, make sure it is stored in pop.screen + + pending "check inherit checker", -> + + describe "pop.create", -> + -- these need to check parent/child relations and data relations + pending "creates elements with pop.screen by default", -> + pending "creates elements with no parent when you pass false", -> + pending "creates elements with specified parent when passed an element", -> + + describe "pop.update", -> + pending "only updates when data.update is truthy", -> + pending "updates all children", -> + + describe "pop.draw", -> + pending "draws elements only when data.draw is truthy", -> + pending "draws all children", -> + + describe "pop.mousemoved", -> + pending "handles mousemoved events on a focused element", -> + --idk exactly how to make a unit test for this... + + describe "pop.mousepressed", -> + pending "idk", -> + + describe "pop.mousereleased", -> + + describe "click handling", -> + + describe "mouserelease handling", -> + + describe "pop.keypressed", -> + pending "idk", -> + + describe "pop.keyreleased", -> + pending "idk", -> + + describe "pop.textinput", -> + pending "idk", -> + + describe "pop.debugDraw", -> + pending "idk", -> + + describe "pop.printElementTree", -> + pending "idk", -> diff --git a/util.moon b/util.moon index 47305a1..fd9bc5e 100644 --- a/util.moon +++ b/util.moon @@ -2,7 +2,7 @@ --- @module util --- @copyright Paul Liverman III (2015-2016) --- @license The MIT License (MIT) ---- @release v0.0.0 +--- @release 0.0.0 --- @function inheritsFromElement --- @param object A table (MoonScript object expected) to be checked for inheritence from the "element" element.