mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
simplify setContentSize logic
This commit is contained in:
@@ -382,37 +382,7 @@ _ccsg.Label = _ccsg.Node.extend({
|
||||
return;
|
||||
}
|
||||
|
||||
var oldWidth = this._contentSize.width;
|
||||
var oldHeight = this._contentSize.height;
|
||||
if (this._labelType === _ccsg.Label.Type.TTF ||
|
||||
this._labelType === _ccsg.Label.Type.SystemFont) {
|
||||
_ccsg.Node.prototype.setContentSize.call(this, size, height);
|
||||
if (oldWidth === this._contentSize.width && oldHeight === this._contentSize.height) {
|
||||
return;
|
||||
}
|
||||
var newWidth = size.width || size;
|
||||
var newHeight = size.height || height;
|
||||
this._labelWidth = newWidth;
|
||||
this._labelHeight = newHeight;
|
||||
this._labelDimensions.width = newWidth;
|
||||
this._labelDimensions.height = newHeight;
|
||||
|
||||
this._maxLineWidth = newWidth;
|
||||
|
||||
this._notifyLabelSkinDirty();
|
||||
} else if (this._labelType === _ccsg.Label.Type.BMFont) {
|
||||
if (!height) {
|
||||
if (oldWidth === size.width && oldHeight === size.height) {
|
||||
return;
|
||||
}
|
||||
this._setDimensions(size.width, size.height);
|
||||
} else {
|
||||
if (oldWidth === size && oldHeight === height) {
|
||||
return;
|
||||
}
|
||||
this._setDimensions(size, height);
|
||||
}
|
||||
}
|
||||
this._setDimensions(size, height);
|
||||
},
|
||||
|
||||
setBlendFunc: function(src, dst) {
|
||||
@@ -625,18 +595,31 @@ cc.BMFontHelper = {
|
||||
this._lettersInfo[letterIndex]._positionY = letterPosition.y;
|
||||
},
|
||||
|
||||
_setDimensions: function(width, height) {
|
||||
if (this._overFlow === _ccsg.Label.Overflow.RESIZE_HEIGHT) {
|
||||
height = 0;
|
||||
}
|
||||
if (height !== this._labelHeight || width !== this._labelWidth) {
|
||||
this._labelWidth = width;
|
||||
this._labelHeight = height;
|
||||
this._labelDimensions.width = width;
|
||||
this._labelDimensions.height = height;
|
||||
_setDimensions: function(size, height) {
|
||||
var newWidth = size.width || size;
|
||||
var newHeight = size.height || height;
|
||||
|
||||
this._maxLineWidth = width;
|
||||
if (this._overFlow === _ccsg.Label.Overflow.SHRINK) {
|
||||
if (this._overFlow === _ccsg.Label.Overflow.RESIZE_HEIGHT) {
|
||||
newHeight = 0;
|
||||
}
|
||||
|
||||
if (this._overFlow === _ccsg.Label.Overflow.NONE) {
|
||||
newWidth = 0;
|
||||
newHeight = 0;
|
||||
}
|
||||
|
||||
if (newHeight !== this._labelHeight || newWidth !== this._labelWidth) {
|
||||
_ccsg.Node.prototype.setContentSize.call(this, size, height);
|
||||
|
||||
this._labelWidth = newWidth;
|
||||
this._labelHeight = newHeight;
|
||||
this._labelDimensions.width = newWidth;
|
||||
this._labelDimensions.height = newHeight;
|
||||
|
||||
this._maxLineWidth = newWidth;
|
||||
|
||||
if (this._labelType === _ccsg.Label.Type.BMFont
|
||||
&& this._overFlow === _ccsg.Label.Overflow.SHRINK) {
|
||||
if (this._bmFontSize > 0) {
|
||||
this._restoreFontSize();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user