mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-19 14:52:40 +08:00
62bd937e7e
`View.setDesignResolutionSize` regenerated the visible size with `viewport / scale`. Because `scale` is itself the rounded `container / design` quotient, that round trip loses one ULP: a 1080x1920 design on a 1532x1532 viewport produces `1919.9999999999998` instead of `1920`. Those values are written by `Widget` into `UITransform._contentSize` and `Node._lpos`, and by `Canvas` into `Camera._orthoHeight`, so the error ends up in the saved `.scene`/`.prefab` files and makes the editor produce diff churn whenever it recomputes the layout. A resolution policy now reports the pair of lengths its scale was derived from (`pixels`: the container length in device pixels, `units`: the same length in UI units) instead of the rounded scale, and the viewport is converted with those two lengths. EXACT_FIT, SHOW_ALL, NO_BORDER, FIXED_HEIGHT and FIXED_WIDTH all report their pair in place. The scale is no longer stored anywhere: `AdaptResult` carries `ratioX` / `ratioY` only, and `getScaleX()` / `getScaleY()` derive `pixels / units` on demand, so the ratio and the scale cannot diverge. `toUISpace()` / `toPixelSpace()` are exported next to `ScaleRatio`, and `View.getRatioX()` / `View.getRatioY()` expose the pair, so any caller can convert lengths without the lossy `pixels / scale` round trip. The camera still frames the whole window (`windowSize.height / scaleY / 2`), but now converts through `toUISpace(size.height, view.getRatioY())`, so a 1532px tall viewport produces exactly 960 instead of 959.9999999999999. No adaptation, layout or rendering semantics change. Note for custom resolution policies: `AdaptResult` no longer carries `scale`. A custom content strategy has to report `ratioX` / `ratioY`; when it does not, the ratios of the previous policy application are kept and the scale is not updated. `AdaptResult` and `ContentStrategy` are engine-private classes, so this only affects strategies passed to `new ResolutionPolicy(...)`. Co-authored-by: Tianze-Chen <tianze@local>