From e45c5cd1a92b7f86ee89d542e89494fd6ece6c56 Mon Sep 17 00:00:00 2001 From: knox Date: Fri, 4 May 2018 09:57:43 +0800 Subject: [PATCH] improve code --- cocos2d/core/components/CCLayout.js | 37 +++++++++++++---------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/cocos2d/core/components/CCLayout.js b/cocos2d/core/components/CCLayout.js index 7d6e2ffa3b..37440838e0 100644 --- a/cocos2d/core/components/CCLayout.js +++ b/cocos2d/core/components/CCLayout.js @@ -525,10 +525,9 @@ var Layout = cc.Class({ var activeChildCount = 0; for (var i = 0; i < children.length; ++i) { var child = children[i]; - if (!child.activeInHierarchy) { - continue; + if (child.activeInHierarchy) { + activeChildCount++; } - activeChildCount++; } var newChildWidth = this.cellSize.width; @@ -630,11 +629,10 @@ var Layout = cc.Class({ if (this.resizeMode === ResizeMode.CONTAINER) { for (var i = 0; i < children.length; ++i) { var child = children[i]; - if (!child.activeInHierarchy) { - continue; + if (child.activeInHierarchy) { + activeChildCount++; + newHeight += child.height; } - activeChildCount++; - newHeight += child.height; } newHeight += (activeChildCount - 1) * this.spacingY + this.paddingBottom + this.paddingTop; @@ -669,10 +667,9 @@ var Layout = cc.Class({ var activeChildCount = 0; for (var i = 0; i < children.length; ++i) { var child = children[i]; - if (!child.activeInHierarchy) { - continue; + if (child.activeInHierarchy) { + activeChildCount++; } - activeChildCount++; } var newChildHeight = this.cellSize.height; @@ -777,13 +774,12 @@ var Layout = cc.Class({ for (var i = 0; i < children.length; ++i) { var child = children[i]; - if (!child.activeInHierarchy) { - continue; - } - if (!allChildrenBoundingBox) { - allChildrenBoundingBox = child.getBoundingBoxToWorld(); - } else { - allChildrenBoundingBox = cc.rectUnion(allChildrenBoundingBox, child.getBoundingBoxToWorld()); + if (child.activeInHierarchy) { + if (!allChildrenBoundingBox) { + allChildrenBoundingBox = child.getBoundingBoxToWorld(); + } else { + allChildrenBoundingBox = cc.rectUnion(allChildrenBoundingBox, child.getBoundingBoxToWorld()); + } } } @@ -908,11 +904,10 @@ var Layout = cc.Class({ if (this.resizeMode === ResizeMode.CONTAINER) { for (var i = 0; i < children.length; ++i) { var child = children[i]; - if (!child.activeInHierarchy) { - continue; + if (child.activeInHierarchy) { + activeChildCount++; + newWidth += child.width; } - activeChildCount++; - newWidth += child.width; } newWidth += (activeChildCount - 1) * this.spacingX + this.paddingLeft + this.paddingRight; }