Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify the behavior of the Label component when the node size changes. #5908

Merged
merged 2 commits into from Dec 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions cocos2d/core/components/CCLabel.js
Expand Up @@ -542,15 +542,15 @@ let Label = cc.Class({
this._super();

// Keep track of Node size
this.node.on(cc.Node.EventType.SIZE_CHANGED, this.setVertsDirty, this);
this.node.on(cc.Node.EventType.SIZE_CHANGED, this._nodeSizeChanged, this);
this.node.on(cc.Node.EventType.ANCHOR_CHANGED, this.setVertsDirty, this);

this._forceUpdateRenderData();
},

onDisable () {
this._super();
this.node.off(cc.Node.EventType.SIZE_CHANGED, this.setVertsDirty, this);
this.node.off(cc.Node.EventType.SIZE_CHANGED, this._nodeSizeChanged, this);
this.node.off(cc.Node.EventType.ANCHOR_CHANGED, this.setVertsDirty, this);
},

Expand All @@ -565,6 +565,15 @@ let Label = cc.Class({
this._super();
},

_nodeSizeChanged () {
if (CC_EDITOR) return;
// Because the content size is automatically updated when overflow is NONE.
// And this will conflict with the alignment of the CCWidget.
if (this.overflow !== Overflow.NONE) {
this.setVertsDirty();
}
},

_updateColor () {
if (!(this.font instanceof cc.BitmapFont)) {
this.setVertsDirty();
Expand Down