Merge branch 'elemental-handling' of github.com:Guard13007/Pop.Box into elemental-handling

This commit is contained in:
Paul Liverman 2016-04-01 14:16:31 -07:00
commit 25f77d8d16
3 changed files with 47 additions and 17 deletions

View File

@ -59,14 +59,31 @@ pop.load = function()
pop.screen = pop.create("element", false):setSize(graphics.getWidth(), graphics.getHeight()) pop.screen = pop.create("element", false):setSize(graphics.getWidth(), graphics.getHeight())
return print("created \"pop.screen\"") return print("created \"pop.screen\"")
end end
local instanceOfElement
instanceOfElement = function(object)
if object and object.__class then
local cls = object.__class
if cls.__name == "element" then
return true
end
while cls.__parent do
cls = cls.__parent
if cls.__name == "element" then
return true
end
end
end
return false
end
pop.create = function(element, parent, ...) pop.create = function(element, parent, ...)
if parent == nil then if parent == nil then
parent = pop.screen parent = pop.screen
end end
if parent then if instanceOfElement(parent) then
print(parent.__class, parent.__class.__name, parent.__class.__base, parent.__class.__parent)
end
element = pop.elements[element](parent, ...) element = pop.elements[element](parent, ...)
else
element = pop.elements[element](pop.screen, parent, ...)
end
if parent then if parent then
insert(parent.child, element) insert(parent.child, element)
end end

View File

@ -59,14 +59,31 @@ pop.load = function()
pop.screen = pop.create("element", false):setSize(graphics.getWidth(), graphics.getHeight()) pop.screen = pop.create("element", false):setSize(graphics.getWidth(), graphics.getHeight())
return print("created \"pop.screen\"") return print("created \"pop.screen\"")
end end
local instanceOfElement
instanceOfElement = function(object)
if object and object.__class then
local cls = object.__class
if cls.__name == "element" then
return true
end
while cls.__parent do
cls = cls.__parent
if cls.__name == "element" then
return true
end
end
end
return false
end
pop.create = function(element, parent, ...) pop.create = function(element, parent, ...)
if parent == nil then if parent == nil then
parent = pop.screen parent = pop.screen
end end
if parent then if instanceOfElement(parent) then
print(parent.__class, parent.__class.__name, parent.__class.__base, parent.__class.__parent)
end
element = pop.elements[element](parent, ...) element = pop.elements[element](parent, ...)
else
element = pop.elements[element](pop.screen, parent, ...)
end
if parent then if parent then
insert(parent.child, element) insert(parent.child, element)
end end

View File

@ -62,25 +62,21 @@ pop.load = ->
print "created \"pop.screen\"" print "created \"pop.screen\""
instanceOfElement = (object) -> instanceOfElement = (object) ->
if object.__class if object and object.__class
class = object.__class cls = object.__class
if class.__name == "element" if cls.__name == "element"
return true return true
while class.__parent while cls.__parent
class = class.__parent cls = cls.__parent
if class.__name == "element" if cls.__name == "element"
return true return true
return false return false
-- creates an element with specified parent (parent can be false) -- creates an element with specified parent (parent can be false or non-existent)
pop.create = (element, parent=pop.screen, ...) -> pop.create = (element, parent=pop.screen, ...) ->
--if parent
-- print parent.__class, parent.__class.__name, parent.__class.__base, parent.__class.__parent
--element = pop.elements[element](parent, ...)
if instanceOfElement parent if instanceOfElement parent
element = pop.elements[element](parent, ...) element = pop.elements[element](parent, ...)
else else