diff --git a/cocos/ui/widget-manager.ts b/cocos/ui/widget-manager.ts index ddd6b8aaa1d..b354dd523e5 100644 --- a/cocos/ui/widget-manager.ts +++ b/cocos/ui/widget-manager.ts @@ -26,7 +26,7 @@ import { EDITOR, DEV } from 'internal:constants'; import { screenAdapter } from 'pal/screen-adapter'; import { Director, director } from '../game/director'; -import { Vec2, Vec3, visibleRect, js, cclegacy } from '../core'; +import { Vec2, Vec3, visibleRect, js, cclegacy, approx, EPSILON } from '../core'; import { View } from './view'; import { Scene } from '../scene-graph'; import { Node } from '../scene-graph/node'; @@ -124,6 +124,11 @@ function align (node: Node, widget: Widget) { } else { x = localRight + (anchorX - 1) * width; } + if (!approx(scaleX, 0, EPSILON)) { + width /= scaleX; + } else { + width = uiTrans.width; + } } widget._lastSize.width = width; @@ -182,6 +187,11 @@ function align (node: Node, widget: Widget) { } else { y = localTop + (anchorY - 1) * height; } + if (!approx(scaleY, 0, EPSILON)) { + height /= scaleY; + } else { + height = uiTrans.height; + } } widget._lastSize.height = height;