📄 borderlayout.as
字号:
remainingHeight -= bottomHeight; //the height of the center area affects the height of the left and right areas var centerHeight:Number = Math.max(remainingHeight, 0); //position the left children var leftWidth:Number = 0; var leftChildren:Array = this.getChildrenByConstraint(BorderConstraints.LEFT, true); var leftChildCount:int = leftChildren.length; for(i = 0; i < leftChildCount; i++) { var leftChild:DisplayObject = DisplayObject(leftChildren[i]); config = this.configurations[this.clients.indexOf(leftChild)]; x = START_X + leftWidth; y = START_Y + topHeight; if(config.maintainAspectRatio) { DisplayObjectUtil.resizeAndMaintainAspectRatio(leftChild, leftChild.width, centerHeight, config.aspectRatio); } else { leftChild.height = centerHeight; } DisplayObjectUtil.align(leftChild, new Rectangle(x, y, leftChild.width, centerHeight), config.horizontalAlign, config.verticalAlign); leftWidth += leftChild.width + this.horizontalGap; } remainingWidth -= leftWidth; //position the right children var rightWidth:Number = 0; var rightChildren:Array = this.getChildrenByConstraint(BorderConstraints.RIGHT, true); var rightChildCount:int = rightChildren.length; for(i = 0; i < rightChildCount; i++) { var rightChild:DisplayObject = DisplayObject(rightChildren[i]); config = this.configurations[this.clients.indexOf(rightChild)]; rightWidth += rightChild.width; x = START_X + width - rightWidth; y = START_Y + topHeight; if(config.maintainAspectRatio) { DisplayObjectUtil.resizeAndMaintainAspectRatio(rightChild, rightChild.width, centerHeight, config.aspectRatio); } else { rightChild.height = centerHeight; } DisplayObjectUtil.align(rightChild, new Rectangle(x, y, rightChild.width, centerHeight), config.horizontalAlign, config.verticalAlign); rightWidth += this.horizontalGap; } //if leftWidth + rightWidth < the total width, fix the overlap difference = (START_X + leftWidth) - (START_X + width - rightWidth); if(difference > 0) { for(i = 0; i < rightChildCount; i++) { rightChild = DisplayObject(rightChildren[i]); rightChild.x += difference; } } remainingWidth -= rightWidth; //position the center children in the remaining width var centerWidth:Number = Math.max(remainingWidth, 0); var centerChildren:Array = this.getChildrenByConstraint(BorderConstraints.CENTER, true); var centerChildCount:int = centerChildren.length; var centerChildHeight:Number = centerHeight / centerChildCount; for(i = 0; i < centerChildCount; i++) { var centerChild:DisplayObject = DisplayObject(centerChildren[i]); config = this.configurations[this.clients.indexOf(centerChild)]; x = START_X + leftWidth; y = START_Y + topHeight + (i * centerChildHeight); if(config.maintainAspectRatio) { DisplayObjectUtil.resizeAndMaintainAspectRatio(centerChild, centerWidth, centerChildHeight, config.aspectRatio); } else { centerChild.width = centerWidth; centerChild.height = centerChildHeight; } DisplayObjectUtil.align(centerChild, new Rectangle(x, y, centerWidth, centerChildHeight), config.horizontalAlign, config.verticalAlign); } if(remainingWidth < 0) { width -= remainingWidth; } if(remainingHeight < 0) { height -= remainingHeight; } bounds.width = width + this.paddingLeft + this.paddingRight; bounds.height = height + this.paddingTop + this.paddingBottom; return bounds; } /** * @private * Creates the default configuration for this layout mode. */ override protected function newConfiguration():Object { return { includeInLayout: true, constraint: BorderConstraints.CENTER }; } /** * @private * If no width is specified for the layout container, we need to * measure the children to determine the best width. */ protected function measureChildWidths():Number { var totalWidth:Number = this.paddingLeft + this.paddingRight; var leftChildren:Array = this.getChildrenByConstraint(BorderConstraints.LEFT, true); var childCount:int = leftChildren.length; for(var i:int = 0; i < childCount; i++) { var child:DisplayObject = DisplayObject(leftChildren[i]); totalWidth += child.width + this.horizontalGap; } var rightChildren:Array = this.getChildrenByConstraint(BorderConstraints.RIGHT, true); childCount = rightChildren.length; for(i = 0; i < childCount; i++) { child = DisplayObject(rightChildren[i]); totalWidth += child.width + this.horizontalGap; } var maxWidth:Number = 0; var centerChildren:Array = this.getChildrenByConstraint(BorderConstraints.CENTER, true); childCount = centerChildren.length; for(i = 0; i < childCount; i++) { child = DisplayObject(centerChildren[i]); maxWidth = Math.max(maxWidth, child.width); } totalWidth += maxWidth; maxWidth = 0; var topChildren:Array = this.getChildrenByConstraint(BorderConstraints.TOP, true); childCount = topChildren.length; for(i = 0; i < childCount; i++) { child = DisplayObject(topChildren[i]); maxWidth = Math.max(maxWidth, child.width); } var bottomChildren:Array = this.getChildrenByConstraint(BorderConstraints.BOTTOM, true); childCount = bottomChildren.length; for(i = 0; i < childCount; i++) { child = DisplayObject(bottomChildren[i]); maxWidth = Math.max(maxWidth, child.width); } totalWidth = Math.max(maxWidth, totalWidth); return totalWidth; } /** * @private * If no height is specified for the layout container, we need to * measure the children to determine the best height. */ protected function measureChildHeights():Number { var totalHeight:Number = this.paddingTop + this.paddingBottom; var topChildren:Array = this.getChildrenByConstraint(BorderConstraints.TOP, true); var childCount:int = topChildren.length; for(var i:int = 0; i < childCount; i++) { var child:DisplayObject = DisplayObject(topChildren[i]); totalHeight += child.height; } var bottomChildren:Array = this.getChildrenByConstraint(BorderConstraints.BOTTOM, true); childCount = bottomChildren.length; for(i = 0; i < childCount; i++) { child = DisplayObject(bottomChildren[i]); totalHeight += child.height; } var centerTotalHeight:Number = 0; var centerChildren:Array = this.getChildrenByConstraint(BorderConstraints.CENTER, true); childCount = centerChildren.length; for(i = 0; i < childCount; i++) { child = DisplayObject(centerChildren[i]); centerTotalHeight += child.height; } var maxHeight:Number = centerTotalHeight; var rightChildren:Array = this.getChildrenByConstraint(BorderConstraints.RIGHT, true); childCount = rightChildren.length; for(i = 0; i < childCount; i++) { child = DisplayObject(rightChildren[i]); maxHeight = Math.max(maxHeight, child.height); } var leftChildren:Array = this.getChildrenByConstraint(BorderConstraints.LEFT, true); childCount = leftChildren.length; for(i = 0; i < childCount; i++) { child = DisplayObject(leftChildren[i]); maxHeight = Math.max(maxHeight, child.height); } totalHeight += maxHeight; return totalHeight; } /** * @private * A simple filter for getting all the clients with a specific constraint * in their configuration. */ protected function getChildrenByConstraint(constraint:String, inLayoutOnly:Boolean = false):Array { return this.clients.filter(function(item:DisplayObject, index:int, source:Array):Boolean { var configuration:Object = this.configurations[index]; return configuration.constraint == constraint && (inLayoutOnly ? configuration.includeInLayout : true); }, this); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -