mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
made parents completely optional in element creation
This commit is contained in:
parent
3c1724d9fb
commit
cd64ba6b81
@ -59,14 +59,31 @@ pop.load = function()
|
||||
pop.screen = pop.create("element", false):setSize(graphics.getWidth(), graphics.getHeight())
|
||||
return print("created \"pop.screen\"")
|
||||
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, ...)
|
||||
if parent == nil then
|
||||
parent = pop.screen
|
||||
end
|
||||
if parent then
|
||||
print(parent.__class, parent.__class.__name, parent.__class.__base, parent.__class.__parent)
|
||||
if instanceOfElement(parent) then
|
||||
element = pop.elements[element](parent, ...)
|
||||
else
|
||||
element = pop.elements[element](pop.screen, parent, ...)
|
||||
end
|
||||
element = pop.elements[element](parent, ...)
|
||||
if parent then
|
||||
insert(parent.child, element)
|
||||
end
|
||||
|
@ -59,14 +59,31 @@ pop.load = function()
|
||||
pop.screen = pop.create("element", false):setSize(graphics.getWidth(), graphics.getHeight())
|
||||
return print("created \"pop.screen\"")
|
||||
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, ...)
|
||||
if parent == nil then
|
||||
parent = pop.screen
|
||||
end
|
||||
if parent then
|
||||
print(parent.__class, parent.__class.__name, parent.__class.__base, parent.__class.__parent)
|
||||
if instanceOfElement(parent) then
|
||||
element = pop.elements[element](parent, ...)
|
||||
else
|
||||
element = pop.elements[element](pop.screen, parent, ...)
|
||||
end
|
||||
element = pop.elements[element](parent, ...)
|
||||
if parent then
|
||||
insert(parent.child, element)
|
||||
end
|
||||
|
@ -52,25 +52,21 @@ pop.load = ->
|
||||
print "created \"pop.screen\""
|
||||
|
||||
instanceOfElement = (object) ->
|
||||
if object.__class
|
||||
class = object.__class
|
||||
if object and object.__class
|
||||
cls = object.__class
|
||||
|
||||
if class.__name == "element"
|
||||
if cls.__name == "element"
|
||||
return true
|
||||
|
||||
while class.__parent
|
||||
class = class.__parent
|
||||
if class.__name == "element"
|
||||
while cls.__parent
|
||||
cls = cls.__parent
|
||||
if cls.__name == "element"
|
||||
return true
|
||||
|
||||
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, ...) ->
|
||||
--if parent
|
||||
-- print parent.__class, parent.__class.__name, parent.__class.__base, parent.__class.__parent
|
||||
--element = pop.elements[element](parent, ...)
|
||||
|
||||
if instanceOfElement parent
|
||||
element = pop.elements[element](parent, ...)
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user