fix widget bug (#4749)

* fix widget bug

* fix circle
This commit is contained in:
JoneLau
2019-07-01 09:35:53 +08:00
committed by Weiliang Wang
parent 366d46ba99
commit f2f9514aa3
2 changed files with 27 additions and 6 deletions
+26 -6
View File
@@ -30,6 +30,7 @@
import { Component} from '../../../components';
import { ccclass, executeInEditMode, executionOrder, menu, property, requireComponent } from '../../../core/data/class-decorator';
import { SystemEventType } from '../../../core/platform';
import { Size, Vec3 } from '../../../core/value-types';
import { ccenum } from '../../../core/value-types/enum';
import { Node } from '../../../scene-graph/node';
@@ -138,12 +139,16 @@ export class WidgetComponent extends Component {
return;
}
this._unregisterTargetEvents();
this._target = value;
this._registerTargetEvents();
if (CC_EDITOR /*&& !cc.engine._isPlaying*/ && this.node.parent) {
// adjust the offsets to keep the size and position unchanged after target chagned
cc._widgetManager.updateOffsetsToStayPut(this);
}
this._validateTargetInDEV();
this._recursiveDirty();
}
@@ -566,6 +571,7 @@ export class WidgetComponent extends Component {
this.node.getPosition(this._lastPos);
this.node.getContentSize(this._lastSize);
cc._widgetManager.add(this);
this._registerTargetEvents();
}
public update (){
@@ -573,19 +579,15 @@ export class WidgetComponent extends Component {
return;
}
// changed by parent
if (this.node.hasChanged) {
this._recursiveDirty();
return;
}
if (this.target && this.target.hasChanged){
this._recursiveDirty();
return;
}
}
public onDisable () {
cc._widgetManager.remove(this);
this._unregisterTargetEvents();
}
protected _aotuChangedValue (flag: AlignFlags, isAbs: boolean){
@@ -612,6 +614,24 @@ export class WidgetComponent extends Component {
this._recursiveDirty();
}
protected _registerTargetEvents (){
if (this._target){
this._target.on(SystemEventType.TRANSFORM_CHANGED, this._targetChangedOperation, this);
this._target.on(SystemEventType.SIZE_CHANGED, this._targetChangedOperation, this);
}
}
protected _unregisterTargetEvents () {
if (this._target) {
this._target.off(SystemEventType.TRANSFORM_CHANGED, this._targetChangedOperation, this);
this._target.off(SystemEventType.SIZE_CHANGED, this._targetChangedOperation, this);
}
}
protected _targetChangedOperation (){
this._recursiveDirty();
}
private _setAlign (flag: AlignFlags, isAlign: boolean) {
const current = (this._alignFlags & flag) > 0;
if (isAlign === current) {
+1
View File
@@ -239,6 +239,7 @@ function align (node: Node, widget: WidgetComponent) {
}
node.setPosition(x, y, _tempPos.z);
vec3.set(widget._lastPos, x, y, _tempPos.z);
}
function visitNode (node: Node) {