diff --git a/src/pop/elements/box.moon b/src/pop/elements/box.moon index 2450eb3..5c79ee2 100644 --- a/src/pop/elements/box.moon +++ b/src/pop/elements/box.moon @@ -57,4 +57,4 @@ class box extends element if type(@background) == "table" return unpack @background else - error "This box doesn't have a color." --might be a bad idea + error "Box \"#{@}\" doesn't have a color." --might be a bad idea diff --git a/src/pop/elements/element.moon b/src/pop/elements/element.moon index 536386a..9f6db91 100644 --- a/src/pop/elements/element.moon +++ b/src/pop/elements/element.moon @@ -42,7 +42,7 @@ class element addChild: (child) => -- make sure we don't duplicate references if child.parent - child.parent\removeChild(child) + child.parent\removeChild child insert @child, child child.parent = @ @@ -104,8 +104,7 @@ class element y = oldY for i = 1, #@child - unless @child[i].excludeMovement - @child[i]\move x - oldX, y - oldY + @child[i]\move x - oldX, y - oldY return @ diff --git a/src/pop/elements/text.moon b/src/pop/elements/text.moon index 80d611e..48324f9 100644 --- a/src/pop/elements/text.moon +++ b/src/pop/elements/text.moon @@ -5,7 +5,7 @@ path = sub ..., 1, len(...) - len "/box" element = require "#{path}/element" class text extends element - -- this should be completely unneccessary, but I'm keeping it just in case + -- this should be completely unneccessary, but I'm keeping it just in case (and moreso to remember how to do this) @wrap = (pop) -> return (parent, ...) -> if type(parent) == "string" diff --git a/src/pop/elements/window.moon b/src/pop/elements/window.moon index 9a4aa8c..b1e2049 100644 --- a/src/pop/elements/window.moon +++ b/src/pop/elements/window.moon @@ -1,4 +1,5 @@ import graphics from love +import insert, remove from table import sub, len from string path = sub ..., 1, len(...) - len "/window" @@ -28,11 +29,6 @@ class window extends element load: (pop) -> pop_ref = pop - --wrap: (pop) -> - -- pop_ref = pop -- set our reference to pop (needed for mouse handling) - -- return (...) -> -- standard wrapper, nothing special needed - -- return pop.create("window", ...) - new: (parent, title="window", tBackground={25, 180, 230, 255}, tColor={255, 255, 255, 255}, wBackground={200, 200, 210, 255}) => super parent @@ -52,15 +48,12 @@ class window extends element @head, @title, @window } - --@selected = false -- whether or not the window title (and thus, the window) has been selected - --NOTE all of these commented out, because I realized these event handlers should be attached to the title element - @head.selected = false -- whether or not the window title (and thus, the window) has been selected if mousemoved_event @head.mousemoved = (x, y, dx, dy) => if @selected - -- for some reason, y and dx are actually dx and dy...what the fuck? (note: in version 0.10.0) + -- for some reason, y and dx are actually dx and dy...what the fuck? (note: in version 0.10.0 AND 0.10.1) @parent\move y, dx --dx, dy return true return false @@ -110,11 +103,18 @@ class window extends element return @ addChild: (child) => - @window.child[#@window.child+1] = child - child.parent = @window + @window\addChild child return @ + -- pass through to window, but return us if window returns itself + removeChild: (child) => + result = @window\removeChild child + if result == @window + return @ + else + return result + getChildren: => return @window.child diff --git a/src/pop/init.moon b/src/pop/init.moon index 73c8370..a74017c 100644 --- a/src/pop/init.moon +++ b/src/pop/init.moon @@ -13,7 +13,7 @@ pop.elements = {} pop.skins = {} pop.events = {} -pop.screen = false -- initialized in pop.load() +pop.screen = false -- initialized in pop.load() pop.focused = false -- loads elements and skins, creates pop.screen (intended to only be called once at the beginning) @@ -68,17 +68,20 @@ pop.load = -> print "extension loaded: \"#{name}\"" - -- main window (called screen because there will be a window element class) + -- main window (called screen because there is a window element class) pop.screen = pop.create("element", false)\setSize(graphics.getWidth!, graphics.getHeight!) print "created \"pop.screen\"" -- creates an element with specified parent (parent can be false or non-existent) pop.create = (element, parent=pop.screen, ...) -> + -- if valid parent element (includes default of pop.screen when no parent has been passed) if inheritsFromElement parent element = pop.elements[element](parent, ...) insert parent.child, element + -- if explicitly no parent elseif parent == false element = pop.elements[element](false, ...) + -- else we use pop.screen, and "parent" is actually first argument else element = pop.elements[element](pop.screen, parent, ...) insert pop.screen.child, element @@ -86,7 +89,6 @@ pop.create = (element, parent=pop.screen, ...) -> return element pop.update = (dt, element=pop.screen) -> - --pop.screen\update dt unless element.excludeUpdate if element.update element\update dt @@ -94,7 +96,6 @@ pop.update = (dt, element=pop.screen) -> pop.update dt, element.child[i] pop.draw = (element=pop.screen) -> - --pop.screen\draw! unless element.excludeDraw if element.draw element\draw!