From 035e94bd51b8192e2453ca666403f15ef66b54cb Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 11 Jan 2016 20:13:52 +0800 Subject: [PATCH] make code more readable --- cocos2d/core/label/CCSGLabel.js | 41 ++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js index 0fcd3c4004..65dd0fe6f1 100644 --- a/cocos2d/core/label/CCSGLabel.js +++ b/cocos2d/core/label/CCSGLabel.js @@ -256,26 +256,41 @@ _ccsg.Label = _ccsg.Node.extend({ return this._fontSize; }, + _updateWrapText: function(overflow){ + if ( overflow === _ccsg.Label.Overflow.RESIZE_HEIGHT) { + this._isWrapText = true; + } + + if (overflow === _ccsg.Label.Overflow.NONE) { + this._isWrapText = false; + } + }, + + + _setOverflowBMFont: function () { + if (this._labelType === _ccsg.Label.Type.BMFont) { + + if ( this._overFlow === _ccsg.Label.Overflow.RESIZE_HEIGHT) { + this._setDimensions(this._labelDimensions.width, 0); + } + + if (this._overFlow === _ccsg.Label.Overflow.NONE) { + this._setDimensions(0, 0); + } + + this._rescaleWithOriginalFontSize(); + } + }, + setOverflow: function(overflow) { if (this._overFlow === overflow) return; this._overFlow = overflow; - if (this._labelType === _ccsg.Label.Type.BMFont) { + this._updateWrapText(this._overFlow); - if ( this._overFlow === _ccsg.Label.Overflow.RESIZE_HEIGHT) { - this._setDimensions(this._labelDimensions.width, 0); - this._isWrapText = true; - } + this._setOverflowBMFont(); - if (this._overFlow === _ccsg.Label.Overflow.NONE) { - this._isWrapText = false; - this._setDimensions(0, 0); - } - } - - - this._rescaleWithOriginalFontSize(); this._notifyLabelSkinDirty(); },