From e548456366a412c6a15e3d992f90292376225a35 Mon Sep 17 00:00:00 2001 From: Paul Liverman III Date: Mon, 22 Aug 2016 18:19:58 -0700 Subject: [PATCH] docs updates --- Element.luadoc | 67 ++++++++++++---------------- docs/classes/element.html | 43 +++++++++++++++--- docs/index.html | 2 +- docs/modules/Element.html | 93 ++++++++++++++++++++++++++++++++++++++- docs/modules/main.html | 2 +- docs/modules/pop.html | 2 +- docs/modules/util.html | 2 +- elements/element.lua | 7 ++- elements/element.moon | 6 +-- init.lua | 6 +-- init.moon | 10 ++--- 11 files changed, 179 insertions(+), 61 deletions(-) diff --git a/Element.luadoc b/Element.luadoc index 33738b4..b1409dd 100644 --- a/Element.luadoc +++ b/Element.luadoc @@ -48,6 +48,31 @@ --- LÖVE version.) --- @treturn boolean Was the event handled? +--- **Optional**: Called from `pop.mousereleased()` if a mouse button was +--- pressed and then released over your element. +--- +--- **Note**: Your element must be visible (`data.draw` is true) for this method +--- to be called. +--- @function clicked +--- @tparam integer x The x coordinate of the mouse click relative to the +--- element. +--- @tparam integer y The y coordinate of the mouse click relative to the +--- element. +--- @tparam ?string|integer button The mouse button clicked. (Type varies by +--- LÖVE version.) +--- @treturn boolean Was the event handled? + +--- **Optional**: Called from `pop.mousereleased()` if a mouse button was +--- released over your element. +--- @function mousereleased +--- @tparam integer x The x coordinate of the mouse release relative to the +--- element. +--- @tparam integer y The y coordinate of the mouse release relative to the +--- element. +--- @tparam ?string|integer button The mouse button released. (Type varies by +--- LÖVE version.) +--- @treturn boolean Was the event handled? + --- The parent element of this element. @@ -76,15 +101,10 @@ -pop.mousereleased = (x, y, button, element) -> - if element.clicked and element.data.draw - clickedHandled = element\clicked x - element.data.x, y - element.data.y, button - if element.mousereleased - mousereleasedHandled = element\mousereleased x - element.data.x, y - element.data.y, button - - -- if we clicked, we're focused! - if clickedHandled - pop.focused = element +-- @todo Document keypressed method +-- @todo Document keyreleased method +-- @todo Document textinput method +-- @todo Document debugDraw method pop.keypressed = (key) -> print "keypressed", key @@ -119,32 +139,3 @@ pop.textinput = (text) -> pop.debugDraw = (element=pop.screen) -> if element.debugDraw element\debugDraw! - else - graphics.setLineWidth 1 - graphics.setLineColor 0, 0, 0, 100 - graphics.rectangle "fill", element.x, element.y, element.w, element.h - graphics.setColor 150, 150, 150, 150 - graphics.rectangle "line", element.x, element.y, element.w, element.h - graphics.setColor 200, 200, 200, 255 - graphics.print ".", element.x, element.y - - for i = 1, #element.child - pop.debugDraw element.child[i] - -pop.printElementTree = (element=pop.screen, depth=0) -> - cls = element.__class.__name - - if cls == "text" - cls = cls .. " (\"#{element\getText!\gsub "\n", "\\n"}\")" - elseif cls == "box" - bg = element\getBackground! - - if type(bg) == "table" - bg = "#{bg[1]}, #{bg[2]}, #{bg[3]}, #{bg[4]}" - - cls = cls .. " (#{bg})" - - print string.rep("-", depth) .. " #{cls}" - - for i = 1, #element.child - pop.printElementTree element.child[i], depth + 1 diff --git a/docs/classes/element.html b/docs/classes/element.html index 1224fdf..02998e8 100644 --- a/docs/classes/element.html +++ b/docs/classes/element.html @@ -32,6 +32,7 @@

Contents

@@ -64,11 +65,18 @@ +

Issues

+ + + + + +
element.new-todo5if data, do stuff about it

Methods

- - + +
element.new (self, parent)Constructor expects nothing?element.new (self, @, @)Constructor expects nothing, or a data table describing it.
@@ -76,15 +84,33 @@
+

Issues

+ +
+
+ + element.new-todo5 +
+
+ if data, do stuff about it + + + + + + + +
+

Methods

- element.new (self, parent) + element.new (self, @, @)
- Constructor expects nothing? + Constructor expects nothing, or a data table describing it.

Parameters:

@@ -94,7 +120,12 @@ -
  • parent +
  • @ + + + +
  • +
  • @ @@ -113,7 +144,7 @@
    generated by LDoc 1.4.3 -Last updated 2016-08-21 00:47:30 +Last updated 2016-08-22 18:19:38
    diff --git a/docs/index.html b/docs/index.html index bd04f05..ac5893b 100644 --- a/docs/index.html +++ b/docs/index.html @@ -79,7 +79,7 @@
    generated by LDoc 1.4.3 -Last updated 2016-08-21 00:47:30 +Last updated 2016-08-22 18:19:38
    diff --git a/docs/modules/Element.html b/docs/modules/Element.html index bc4788a..4fc6ba7 100644 --- a/docs/modules/Element.html +++ b/docs/modules/Element.html @@ -92,6 +92,16 @@ Optional: Called from pop.mousepressed() if a mouse button was pressed over your element. + + clicked (x, y, button) + Optional: Called from pop.mousereleased() if a mouse button was + pressed and then released over your element. + + + mousereleased (x, y, button) + Optional: Called from pop.mousereleased() if a mouse button was + released over your element. +

    Tables

    @@ -285,6 +295,87 @@ + +
    + + clicked (x, y, button) +
    +
    + Optional: Called from pop.mousereleased() if a mouse button was + pressed and then released over your element.

    + +

    Note: Your element must be visible (data.draw is true) for this method + to be called. + + +

    Parameters:

    +
      +
    • x + integer + The x coordinate of the mouse click relative to the + element. +
    • +
    • y + integer + The y coordinate of the mouse click relative to the + element. +
    • +
    • button + string or integer + The mouse button clicked. (Type varies by + LÖVE version.) +
    • +
    + +

    Returns:

    +
      + + boolean + Was the event handled? +
    + + + + +
    +
    + + mousereleased (x, y, button) +
    +
    + Optional: Called from pop.mousereleased() if a mouse button was + released over your element. + + +

    Parameters:

    +
      +
    • x + integer + The x coordinate of the mouse release relative to the + element. +
    • +
    • y + integer + The y coordinate of the mouse release relative to the + element. +
    • +
    • button + string or integer + The mouse button released. (Type varies by + LÖVE version.) +
    • +
    + +

    Returns:

    +
      + + boolean + Was the event handled? +
    + + + +

    Tables

    @@ -395,7 +486,7 @@
    generated by LDoc 1.4.3 -Last updated 2016-08-21 00:47:30 +Last updated 2016-08-22 18:19:38
    diff --git a/docs/modules/main.html b/docs/modules/main.html index 7f1d7ea..9fab2cb 100644 --- a/docs/modules/main.html +++ b/docs/modules/main.html @@ -71,7 +71,7 @@
    generated by LDoc 1.4.3 -Last updated 2016-08-21 00:47:30 +Last updated 2016-08-22 18:19:38
    diff --git a/docs/modules/pop.html b/docs/modules/pop.html index 06a1671..3cc799e 100644 --- a/docs/modules/pop.html +++ b/docs/modules/pop.html @@ -665,7 +665,7 @@ table.insert element.parent, element.parent\removeChild(element),
    generated by LDoc 1.4.3 -Last updated 2016-08-21 00:47:30 +Last updated 2016-08-22 18:19:38
    diff --git a/docs/modules/util.html b/docs/modules/util.html index 135a0fe..490cef9 100644 --- a/docs/modules/util.html +++ b/docs/modules/util.html @@ -125,7 +125,7 @@
    generated by LDoc 1.4.3 -Last updated 2016-08-21 00:47:30 +Last updated 2016-08-22 18:19:38
    diff --git a/elements/element.lua b/elements/element.lua index 0ace973..b8f0dd4 100644 --- a/elements/element.lua +++ b/elements/element.lua @@ -6,7 +6,12 @@ do } _base_0.__index = _base_0 _class_0 = setmetatable({ - __init = function(self, parent) end, + __init = function(self, parent, data) + if data == nil then + data = { } + end + self.parent, self.data = parent, data + end, __base = _base_0, __name = "element" }, { diff --git a/elements/element.moon b/elements/element.moon index 2ce143f..6c71289 100644 --- a/elements/element.moon +++ b/elements/element.moon @@ -4,9 +4,9 @@ --- @license The MIT License (MIT) class element - --- Constructor expects nothing? - new: (parent) => - --do stuff + --- Constructor expects nothing, or a data table describing it. + new: (@parent, @data={}) => + --- @todo if data, do stuff about it setSize: => --do more stuff! diff --git a/init.lua b/init.lua index 4f11b88..7be63f9 100644 --- a/init.lua +++ b/init.lua @@ -248,11 +248,11 @@ pop.debugDraw = function(element) else graphics.setLineWidth(1) graphics.setLineColor(0, 0, 0, 100) - graphics.rectangle("fill", element.x, element.y, element.w, element.h) + graphics.rectangle("fill", element.data.x, element.data.y, element.data.w, element.data.h) graphics.setColor(150, 150, 150, 150) - graphics.rectangle("line", element.x, element.y, element.w, element.h) + graphics.rectangle("line", element.data.x, element.data.y, element.data.w, element.data.h) graphics.setColor(200, 200, 200, 255) - graphics.print(".", element.x, element.y) + graphics.print(".", element.data.x, element.data.y) end for i = 1, #element.child do pop.debugDraw(element.child[i]) diff --git a/init.moon b/init.moon index 95dfa1e..5a74695 100644 --- a/init.moon +++ b/init.moon @@ -142,7 +142,7 @@ pop.create = (element, parent=pop.screen, ...) -> element = pop.elements[element](parent, ...) insert parent.child, element insert parent.data.child, element.data - element.parent = parent + element.parent = parent --this should already have been set by the element, this is here as a precaution element.data.parent = parent.data -- if explicitly no parent, just create the element elseif parent == false @@ -154,7 +154,7 @@ pop.create = (element, parent=pop.screen, ...) -> element = pop.elements[element](pop.screen, parent, ...) insert pop.screen.child, element insert pop.screen.data.child, element.data - element.parent = pop.screen + element.parent = pop.screen --this should already have been set by the element, this is here as a precaution element.data.parent = pop.screen.data return element @@ -369,11 +369,11 @@ pop.debugDraw = (element=pop.screen) -> else graphics.setLineWidth 1 graphics.setLineColor 0, 0, 0, 100 - graphics.rectangle "fill", element.x, element.y, element.w, element.h + graphics.rectangle "fill", element.data.x, element.data.y, element.data.w, element.data.h graphics.setColor 150, 150, 150, 150 - graphics.rectangle "line", element.x, element.y, element.w, element.h + graphics.rectangle "line", element.data.x, element.data.y, element.data.w, element.data.h graphics.setColor 200, 200, 200, 255 - graphics.print ".", element.x, element.y + graphics.print ".", element.data.x, element.data.y for i = 1, #element.child pop.debugDraw element.child[i]