Improvements in Containers

This commit is contained in:
Luis Fernando Molina committed 2019-04-10 13:34:07 +02:00
1 parent ca15ff0fed
commit f665ebf6a7
8 files changed
+117 -106

No files matched your search

+54 -15
View File
@@ -1,6 +1,6 @@
function newContainer () {
var container = {
let thisObject = {
frame: undefined,
displacement: undefined,
eventHandler: undefined,
@@ -9,24 +9,63 @@ function newContainer () {
isClickeable: false,
isWheelable: false,
name: undefined,
initialize: initialize
initialize: initialize,
connectToParent: connectToParent
}
return container
let connectedToParentWidth = false
let connectedToParentHeight = false
function initialize () {
var frame = newFrame()
frame.initialize()
this.frame = frame
frame.container = container
return thisObject
var eventHandler = newEventHandler()
eventHandler.initialize()
eventHandler.name = container.name
this.eventHandler = eventHandler
function initialize (pName) {
thisObject.name = pName
var displacement = newDisplacement()
this.displacement = displacement
displacement.container = container
thisObject.frame = newFrame()
thisObject.frame.initialize()
thisObject.frame.containerName = pName
thisObject.frame.container = thisObject
thisObject.eventHandler = newEventHandler()
thisObject.eventHandler.initialize()
thisObject.eventHandler.name = pName
thisObject.displacement = newDisplacement()
thisObject.displacement.container = thisObject
thisObject.displacement.containerName = pName
}
function connectToParent (parentContainer, onWidth, onHeight) {
connectedToParentWidth = onWidth
connectedToParentHeight = onHeight
thisObject.displacement.parentDisplacement = parentContainer.displacement
thisObject.frame.parentFrame = parentContainer.frame
thisObject.parentContainer = parentContainer
thisObject.parentContainer.eventHandler.listenToEvent('Dimmensions Changed', onParentDimmensionsChanged)
if (connectedToParentWidth) {
thisObject.frame.width = thisObject.parentContainer.frame.width
}
if (connectedToParentHeight) {
thisObject.frame.height = thisObject.parentContainer.frame.height
}
}
function onParentDimmensionsChanged () {
let dimmensionsChanged = false
if (connectedToParentWidth) {
thisObject.frame.width = thisObject.parentContainer.frame.width
dimmensionsChanged = true
}
if (connectedToParentHeight) {
thisObject.frame.height = thisObject.parentContainer.frame.height
dimmensionsChanged = true
}
if (dimmensionsChanged) {
thisObject.eventHandler.raiseEvent('Dimmensions Changed')
console.log(thisObject.name + ' new width = ' + thisObject.frame.width)
}
}
}