Skip to content

Commit

Permalink
simple code
Browse files Browse the repository at this point in the history
  • Loading branch information
moshuying committed Jul 26, 2023
1 parent 1fded12 commit 1cfcc1b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cocos/2d/framework/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { NodeEventType } from '../../scene-graph/node-event';
import { align } from 'cocos/ui/widget-manager';

const _worldPos = new Vec3();
const _widget = new Widget()

const RenderMode = Enum({
OVERLAY: 0,
Expand Down Expand Up @@ -128,16 +129,22 @@ export class Canvas extends RenderRoot2D {
protected fitDesignResolution_EDITOR: (() => void) | undefined;

private _renderMode = RenderMode.OVERLAY;
private _tempWidget = new Widget();

constructor () {
super();
this._thisOnCameraResized = this._onResizeCamera.bind(this);
this._tempWidget.alignFlags = AlignFlags.TOP | AlignFlags.BOT | AlignFlags.LEFT | AlignFlags.CENTER | AlignFlags.RIGHT;

if (EDITOR) {
this.fitDesignResolution_EDITOR = (): void => {
align(this.node,this._tempWidget)
if(!this.node.getComponent('cc.Widget')){
// set alignFlags to align this node and uiTransform component
_widget.alignFlags = AlignFlags.TOP | AlignFlags.BOT | AlignFlags.LEFT | AlignFlags.CENTER | AlignFlags.RIGHT;
_widget.target = this.node.parent
align(this.node,_widget)
_widget.target = null
// disable widget to prevent mis-execution
_widget._dirty = false
_widget.enabled = false
}
};
}
}
Expand Down

0 comments on commit 1cfcc1b

Please sign in to comment.