diff --git a/docs/classes/element.html b/docs/classes/element.html index b7bde6f..b0af638 100644 --- a/docs/classes/element.html +++ b/docs/classes/element.html @@ -456,7 +456,7 @@
generated by LDoc 1.4.3 -Last updated 2017-04-09 18:24:55 +Last updated 2017-04-10 20:32:12
diff --git a/docs/classes/window.html b/docs/classes/window.html index 3c347ed..e895d2a 100644 --- a/docs/classes/window.html +++ b/docs/classes/window.html @@ -144,7 +144,7 @@
generated by LDoc 1.4.3 -Last updated 2017-04-09 18:24:55 +Last updated 2017-04-10 20:32:12
diff --git a/docs/index.html b/docs/index.html index 108ed6b..bb75259 100644 --- a/docs/index.html +++ b/docs/index.html @@ -84,7 +84,7 @@
generated by LDoc 1.4.3 -Last updated 2017-04-09 18:24:55 +Last updated 2017-04-10 20:32:12
diff --git a/docs/modules/Element.html b/docs/modules/Element.html index 4347a25..f2645c8 100644 --- a/docs/modules/Element.html +++ b/docs/modules/Element.html @@ -491,7 +491,7 @@
generated by LDoc 1.4.3 -Last updated 2017-04-09 18:24:55 +Last updated 2017-04-10 20:32:12
diff --git a/docs/modules/main.html b/docs/modules/main.html index b7611c8..d28d573 100644 --- a/docs/modules/main.html +++ b/docs/modules/main.html @@ -105,7 +105,7 @@
generated by LDoc 1.4.3 -Last updated 2017-04-09 18:24:55 +Last updated 2017-04-10 20:32:12
diff --git a/docs/modules/pop.html b/docs/modules/pop.html index 85b06f1..9bc57bf 100644 --- a/docs/modules/pop.html +++ b/docs/modules/pop.html @@ -159,7 +159,7 @@ table.insert element.parent, element.parent\removeChild(element), printElementTree-todo6 - Correct this once elements are reimplemented if it needs correction. + Write debugInfo things for elements. @@ -707,7 +707,7 @@ table.insert element.parent, element.parent\removeChild(element), printElementTree-todo6
- Correct this once elements are reimplemented if it needs correction. + Write debugInfo things for elements. @@ -723,7 +723,7 @@ table.insert element.parent, element.parent\removeChild(element),
generated by LDoc 1.4.3 -Last updated 2017-04-09 18:24:55 +Last updated 2017-04-10 20:32:12
diff --git a/docs/modules/util.html b/docs/modules/util.html index 60c4ffb..0a7e0dc 100644 --- a/docs/modules/util.html +++ b/docs/modules/util.html @@ -126,7 +126,7 @@
generated by LDoc 1.4.3 -Last updated 2017-04-09 18:24:55 +Last updated 2017-04-10 20:32:12
diff --git a/elements/element.lua b/elements/element.lua index 4280fc6..15399d3 100644 --- a/elements/element.lua +++ b/elements/element.lua @@ -53,6 +53,7 @@ do if toPixel == nil then toPixel = true end + local dx, dy = self.data.x, self.data.y if x then self.data.x = x end @@ -75,6 +76,13 @@ do self.data.x = floor(self.data.x) self.data.y = floor(self.data.y) end + dx = self.data.x - dx + dy = self.data.y - dy + local _list_0 = self.child + for _index_0 = 1, #_list_0 do + local child = _list_0[_index_0] + child:move(dx, dy) + end return self end, setSize = function(self, w, h) @@ -111,6 +119,11 @@ do if y == nil then y = 0 end + local _list_0 = self.child + for _index_0 = 1, #_list_0 do + local child = _list_0[_index_0] + child:move(x, y) + end self.data.x = self.data.x + x self.data.y = self.data.y + y return self diff --git a/elements/element.moon b/elements/element.moon index 45ae04c..b87a5ad 100644 --- a/elements/element.moon +++ b/elements/element.moon @@ -75,9 +75,13 @@ class element --- @todo document this setPosition: (x, y, toPixel=true) => + dx, dy = @data.x, @data.y + if x + --dx = x - @data.x @data.x = x if y + --dy = y - @data.y @data.y = y switch @data.horizontal @@ -96,6 +100,12 @@ class element @data.x = floor @data.x @data.y = floor @data.y + -- new minus old is difference that children need to be moved + dx = @data.x - dx + dy = @data.y - dy + for child in *@child + child\move dx, dy + return @ --- Sets an element's width/height. Fixes alignment if needed. @@ -145,6 +155,9 @@ class element --- Moves an element by specified x/y. --- @treturn element self move: (x=0, y=0) => + for child in *@child + child\move x, y + @data.x += x @data.y += y return @ diff --git a/init.lua b/init.lua index 38218e2..95d2db3 100644 --- a/init.lua +++ b/init.lua @@ -256,7 +256,7 @@ pop.mousereleased = function(x, y, button, element) local clickedHandled = false local mousereleasedHandled = false if element then - if (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h) then + if element.data.draw and (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h) then for i = #element.child, 1, -1 do clickedHandled, mousereleasedHandled = pop.mousereleased(x, y, button, element.child[i]) if clickedHandled or mousereleasedHandled then @@ -331,16 +331,16 @@ pop.debugDraw = function(element) if element == nil then element = pop.screen end - if element.debugDraw then - element:debugDraw() + graphics.setLineWidth(1) + graphics.setColor(0, 0, 0, 100) + 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.data.x, element.data.y, element.data.w, element.data.h) + graphics.setColor(200, 200, 200, 255) + if element.debugInfo then + graphics.print(tostring(element.__class.__name:sub(1, 1)) .. " (" .. tostring(element:debugInfo()) .. ")", element.data.x, element.data.y) else - graphics.setLineWidth(1) - graphics.setColor(0, 0, 0, 100) - 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.data.x, element.data.y, element.data.w, element.data.h) - graphics.setColor(200, 200, 200, 255) - graphics.print(".", element.data.x, element.data.y) + graphics.print(tostring(element.__class.__name:sub(1, 1)), element.data.x, element.data.y) end for i = 1, #element.child do pop.debugDraw(element.child[i]) @@ -354,14 +354,8 @@ pop.printElementTree = function(element, depth) depth = 0 end local cls = element.__class.__name - if cls == "text" then - cls = cls .. " (\"" .. tostring(element:getText():gsub("\n", "\\n")) .. "\")" - elseif cls == "box" then - local bg = element:getBackground() - if type(bg) == "table" then - bg = tostring(bg[1]) .. ", " .. tostring(bg[2]) .. ", " .. tostring(bg[3]) .. ", " .. tostring(bg[4]) - end - cls = cls .. " (" .. tostring(bg) .. ")" + if element.debugInfo then + cls = tostring(cls) .. " (" .. tostring(element:debugInfo()) .. ")" end if depth > 0 then log(string.rep("-", depth) .. " " .. tostring(cls)) diff --git a/init.moon b/init.moon index 1f60176..6282e98 100644 --- a/init.moon +++ b/init.moon @@ -341,7 +341,7 @@ pop.mousereleased = (x, y, button, element) -> -- if we have an element, and are within its bounds if element - if (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h) + if element.data.draw and (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h) -- check its children in reverse for handling a clicked or mousereleased event for i = #element.child, 1, -1 clickedHandled, mousereleasedHandled = pop.mousereleased x, y, button, element.child[i] @@ -456,17 +456,18 @@ pop.export = (element=pop.screen) -> --- @see Element 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! + --@todo Remove element.debugDraw functions. + graphics.setLineWidth 1 + graphics.setColor 0, 0, 0, 100 + 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.data.x, element.data.y, element.data.w, element.data.h + graphics.setColor 200, 200, 200, 255 + + if element.debugInfo + graphics.print "#{element.__class.__name\sub 1, 1} (#{element\debugInfo!})", element.data.x, element.data.y else - graphics.setLineWidth 1 - graphics.setColor 0, 0, 0, 100 - 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.data.x, element.data.y, element.data.w, element.data.h - graphics.setColor 200, 200, 200, 255 - graphics.print ".", element.data.x, element.data.y + graphics.print "#{element.__class.__name\sub 1, 1}", element.data.x, element.data.y for i = 1, #element.child pop.debugDraw element.child[i] @@ -480,18 +481,11 @@ pop.debugDraw = (element=pop.screen) -> --- @see Element pop.printElementTree = (element=pop.screen, depth=0) -> - --- @todo Correct this once elements are reimplemented if it needs correction. + --- @todo Write debugInfo things for elements. 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})" + if element.debugInfo + cls = "#{cls} (#{element\debugInfo!})" if depth > 0 log string.rep("-", depth) .. " #{cls}"