From 7121cc177372668fade9c8fffbed71d2dd029c11 Mon Sep 17 00:00:00 2001 From: Paul Liverman III Date: Sun, 9 Apr 2017 02:02:14 -0700 Subject: [PATCH] small changes --- docs/classes/element.html | 46 +++++++++++++++++++++++++++++++++++++- docs/classes/window.html | 8 +++---- docs/index.html | 2 +- docs/modules/Element.html | 2 +- docs/modules/main.html | 2 +- docs/modules/pop.html | 2 +- docs/modules/util.html | 2 +- elements/element.lua | 44 +++++++++++++++++++++++++++++++++++- elements/element.moon | 47 ++++++++++++++++++++++++++++++++++++++- init.moon | 2 +- 10 files changed, 144 insertions(+), 13 deletions(-) diff --git a/docs/classes/element.html b/docs/classes/element.html index 04015b0..ba53958 100644 --- a/docs/classes/element.html +++ b/docs/classes/element.html @@ -72,6 +72,10 @@ element.debugDraw-todo7 doc me + + element.debugDraw-todo7-todo8 + document this +

Methods

@@ -111,6 +115,10 @@ + + + +
element.move (self, x, y) Moves an element by specified x/y.
element.delete (self)Deletes references to this element and then deletes it.

@@ -133,6 +141,20 @@ + +
+ + element.debugDraw-todo7-todo8 +
+
+ document this + + + + + + +

Methods

@@ -404,6 +426,28 @@ + +
+ + element.delete (self) +
+
+ Deletes references to this element and then deletes it. + + +

Parameters:

+ + + + + +
@@ -412,7 +456,7 @@
generated by LDoc 1.4.3 -Last updated 2017-04-08 17:10:29 +Last updated 2017-04-09 02:01:53
diff --git a/docs/classes/window.html b/docs/classes/window.html index a398c84..7510ea9 100644 --- a/docs/classes/window.html +++ b/docs/classes/window.html @@ -68,7 +68,7 @@

Issues

- +
window.new-todo8window.new-todo9 if data, do stuff about it
@@ -88,8 +88,8 @@
- - window.new-todo8 + + window.new-todo9
if data, do stuff about it @@ -144,7 +144,7 @@
generated by LDoc 1.4.3 -Last updated 2017-04-08 17:10:29 +Last updated 2017-04-09 02:01:53
diff --git a/docs/index.html b/docs/index.html index 236677d..fd405bc 100644 --- a/docs/index.html +++ b/docs/index.html @@ -84,7 +84,7 @@
generated by LDoc 1.4.3 -Last updated 2017-04-08 17:10:29 +Last updated 2017-04-09 02:01:53
diff --git a/docs/modules/Element.html b/docs/modules/Element.html index e2afd70..d71248a 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-08 17:10:29 +Last updated 2017-04-09 02:01:53
diff --git a/docs/modules/main.html b/docs/modules/main.html index 715d204..35d8039 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-08 17:10:29 +Last updated 2017-04-09 02:01:53
diff --git a/docs/modules/pop.html b/docs/modules/pop.html index 5ac5fa6..d9be5ff 100644 --- a/docs/modules/pop.html +++ b/docs/modules/pop.html @@ -723,7 +723,7 @@ table.insert element.parent, element.parent\removeChild(element),
generated by LDoc 1.4.3 -Last updated 2017-04-08 17:10:29 +Last updated 2017-04-09 02:01:53
diff --git a/docs/modules/util.html b/docs/modules/util.html index 492101e..3e1857a 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-08 17:10:29 +Last updated 2017-04-09 02:01:53
diff --git a/elements/element.lua b/elements/element.lua index b2430d7..b02cf3c 100644 --- a/elements/element.lua +++ b/elements/element.lua @@ -49,6 +49,34 @@ do end return self end, + setPosition = function(self, x, y, toPixel) + if toPixel == nil then + toPixel = true + end + if x then + self.data.x = x + end + if y then + self.data.y = y + end + local _exp_0 = self.data.horizontal + if "center" == _exp_0 then + self.data.x = self.data.x - (self.data.w / 2) + elseif "right" == _exp_0 then + self.data.x = self.data.x - self.data.w + end + local _exp_1 = self.data.vertical + if "center" == _exp_1 then + self.data.y = self.data.y - (self.data.h / 2) + elseif "bottom" == _exp_1 then + self.data.y = self.data.y - self.data.h + end + if toPixel then + self.data.x = floor(self.data.x) + self.data.y = floor(self.data.y) + end + return self + end, setSize = function(self, w, h) if w then self.data.w = w @@ -86,6 +114,20 @@ do self.data.x = self.data.x + x self.data.y = self.data.y + y return self + end, + delete = function(self) + for i = 1, #self.parent.child do + if self.parent.child[i] == self then + table.remove(self.parent.child, i) + break + end + end + for i = 1, #self.parent.data.child do + if self.parent.data.child[i] == self.data then + table.remove(self.parent.data.child, i) + break + end + end end } _base_0.__index = _base_0 @@ -117,7 +159,7 @@ do self.data.h = 0 end if self.data.update == nil then - self.data.update = false + self.data.update = true end if self.data.draw == nil then self.data.draw = true diff --git a/elements/element.moon b/elements/element.moon index 0d6a206..6c7a64a 100644 --- a/elements/element.moon +++ b/elements/element.moon @@ -21,7 +21,7 @@ class element @data.y = 0 unless @data.y @data.w = 0 unless @data.w @data.h = 0 unless @data.h - @data.update = false if @data.update == nil + @data.update = true if @data.update == nil @data.draw = true if @data.draw == nil @data.type = "element" unless @data.type @data.align = true if (@data.align == nil) and @parent @@ -73,6 +73,31 @@ class element return @ + --- @todo document this + setPosition: (x, y, toPixel=true) => + if x + @data.x = x + if y + @data.y = y + + switch @data.horizontal + when "center" + @data.x -= @data.w / 2 + when "right" + @data.x -= @data.w + + switch @data.vertical + when "center" + @data.y -= @data.h / 2 + when "bottom" + @data.y -= @data.h + + if toPixel + @data.x = floor @data.x + @data.y = floor @data.y + + return @ + --- Sets an element's width/height. Fixes alignment if needed. --- @tparam integer w[opt] Width. --- @tparam integer h[opt] Height. @@ -123,3 +148,23 @@ class element @data.x += x @data.y += y return @ + + --- Deletes references to this element and then deletes it. + delete: => + --for i=1, #@child + -- @child[i]\delete! + --@data.child -- for each child, delete its parent ref! + + for i=1, #@parent.child + if @parent.child[i] == @ + table.remove @parent.child, i + break + + for i=1, #@parent.data.child + if @parent.data.child[i] == @data + table.remove @parent.data.child, i + break + + --@parent = nil + --@data.parent = nil -- really should be for all @data -> nil, and for all @ -> nil + --@ = nil diff --git a/init.moon b/init.moon index b6cf021..1f60176 100644 --- a/init.moon +++ b/init.moon @@ -434,7 +434,7 @@ pop.import = (data, parent=pop.screen) -> data = loads(data) element = pop.create(data.type, parent, data) else - element = pop.elements[data.type](parent, data) + element = pop.elements[data.type](parent, data) --why is it not the same as the other way? insert parent.child, element for i = 1, #data.child