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

remove _fitDesignResolution function call in EVENT_AFTER_UPDATE #15802

Merged
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions cocos/2d/framework/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class Canvas extends RenderRoot2D {

protected _thisOnCameraResized: () => void;
// fit canvas node to design resolution
protected _fitDesignResolution: (() => void) | undefined;
protected fitDesignResolution_EDITOR: (() => void) | undefined;

private _pos = new Vec3();
private _renderMode = RenderMode.OVERLAY;
Expand All @@ -134,16 +134,16 @@ export class Canvas extends RenderRoot2D {
this._thisOnCameraResized = this._onResizeCamera.bind(this);

if (EDITOR) {
this._fitDesignResolution = (): void => {
this.fitDesignResolution_EDITOR = (): void => {
// TODO: support paddings of locked widget
this.node.getPosition(this._pos);
const nodeSize = view.getDesignResolutionSize();
Vec3.set(_worldPos, nodeSize.width * 0.5, nodeSize.height * 0.5, 0);
const trans = this.node._uiProps.uiTransformComp!;
Vec3.set(_worldPos, nodeSize.width * trans.anchorX, nodeSize.height * trans.anchorY, 0);

if (!this._pos.equals(_worldPos)) {
this.node.setPosition(_worldPos);
}
const trans = this.node._uiProps.uiTransformComp!;
if (trans.width !== nodeSize.width) {
trans.width = nodeSize.width;
}
Expand All @@ -160,7 +160,7 @@ export class Canvas extends RenderRoot2D {
if (widget) {
widget.updateAlignment();
} else if (EDITOR) {
this._fitDesignResolution!();
this.fitDesignResolution_EDITOR!();
}

if (!EDITOR) {
Expand All @@ -173,9 +173,6 @@ export class Canvas extends RenderRoot2D {
this._onResizeCamera();

if (EDITOR) {
// Constantly align canvas node in edit mode
cclegacy.director.on(cclegacy.Director.EVENT_AFTER_UPDATE, this._fitDesignResolution!, this);

// In Editor can not edit these attrs.
// (Position in Node, contentSize in uiTransform)
// (anchor in uiTransform, but it can edit, this is different from cocos creator)
Expand Down Expand Up @@ -203,11 +200,7 @@ export class Canvas extends RenderRoot2D {
public onDestroy (): void {
super.onDestroy();

if (EDITOR) {
cclegacy.director.off(cclegacy.Director.EVENT_AFTER_UPDATE, this._fitDesignResolution!, this);
} else {
this.node.off(NodeEventType.TRANSFORM_CHANGED, this._thisOnCameraResized);
}
this.node.off(NodeEventType.TRANSFORM_CHANGED, this._thisOnCameraResized);
}

protected _onResizeCamera (): void {
Expand Down