fix(game-ui): preserve expand layout in viewport previews - #111
SuperSuperPepper wants to merge 1 commit into
Conversation
Render preview UI through a transparent camera with its own image target scale factor so editor UiScale does not force post-layout root scaling. Assisted-by: OpenAI GPT-5 (gpt-5)
|
Tested on Windows at 18cae67. The Root causeIn Bevy 0.19 the scale factor is part of the render target's identity, not metadata on it: impl PartialEq for ImageRenderTarget {
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle && FloatOrd(self.scale_factor) == FloatOrd(other.scale_factor)
}
}
A second camera with The per-target scale factor is therefore both what makes the fix work and what breaks compositing. Symptoms
Sharing a target is what makes an attachment-size disagreement possible, so 2 and 3 are the same coin. Two directions
Smaller items
|
A screen canvas previewed over the viewport was scaled only after layout, so `Expand` could not work. Its root is already `100% x 100%`, and a transform can resize the rendered tree but cannot change the width layout resolved against. A 64px bar anchored to the bottom was laid out against the true viewport and then shrunk about its centre, leaving it floating clear of the edge it was pinned to; above the reference resolution the same arithmetic pushed the edges off-screen instead. The runtime does this by moving the global `UiScale` before layout. The editor cannot, because one resource drives every bevy_ui tree in the process, so the preview now reproduces both halves per-canvas: lay the root out in a box of `target / scale` logical pixels, then scale that box by `scale` and translate it so the centre-scaled result stays flush with the target corner. `Fit` is untouched, since its root is the reference box a centre-scale is meant to move, and `Constant` scales by 1.0. The root rect is normally an invariant re-established every frame, so the preview marks the canvases it owns. That marker is deliberately not `Reflect`: a saved scene must never come back exempt from the healer. Also heals the root `UiTransform` back to identity. The old preview wrote its scale there and scene save serializes reflected components, so the factor was baked into `.bsn` files and a shipped game applied it on top of its own `UiScale`. Healing rather than migrating means an already-poisoned scene repairs itself on load. Issue #110 was diagnosed and first fixed by SuperSuperPepper in #111. That approach gave the preview its own camera with a per-target scale factor, which is sound for layout but cannot composite: a scale factor is part of a render target's identity in Bevy 0.19, and two cameras draw onto one image only by sharing a main texture keyed on that identity. The preview camera got its own texture and wrote it out over the scene, blanking the viewport. Closes #110
|
Thanks for this, and sorry to close it rather than merge it. Your diagnosis of #110 was right, and so was the fix: the editor was scaling the tree after layout when the runtime changes the logical size before it, and What changed is only how the preview composites. Giving the preview its own camera with a per-target scale factor is correct for layout, but it cannot draw over the viewport. In Bevy 0.19 a scale factor is part of a render target's identity ( The landed version keeps the root full-target and reproduces the runtime's semantics in the layout instead: lay the root out in a box of It also picked up the persistence risk the issue raised. The old preview wrote its scale to the root Two things from your PR that I'd have missed on my own: Please do send more. This was a good catch and a good read of the problem. |
Render preview UI through a transparent camera with its own image target scale factor so editor UiScale does not force post-layout root scaling.
Assisted-by: OpenAI GPT-5 (gpt-5)
Summary
Fix
Expandcanvas previews so they use the same pre-layout scaling semantics as the runtime.The previous preview path applied
UiTransform.scaleto the canvas root after layout. That could resize the rendered tree, but it could not change the logical width used during layout, so aspect ratios narrower than the reference resolution produced a different layout from the shipped game.This change renders viewport UI through a dedicated transparent UI-only camera. Its image render target uses a per-target scale factor, allowing Bevy to resolve the preview layout with the correct logical size while leaving the editor shell's global
UiScaleunchanged.Changes
UiScale.Expand,Fit, andConstantscale calculations, including the1280x720reference rendered into a1225x551target from [Bug]UiCanvasexpandmode scales the full-size root in Editor viewport previe #110.Related Issues
Closes #110
AI Assistance
Checklist
renzora check)renzora test)mainAssisted-by:commit trailerTesting
Automated checks completed:
The
renzoraCLI and Docker are not installed on the validation host, so thedocumented Cargo commands from the repository's current CI workflow were run
directly instead. The workspace test and Clippy invocations used the workflow's
vendored-crate exclusion lists.
Manual editor verification is still required before submission. The freshly
staged editor launches successfully. With an
Expandcanvas using a1280x720reference resolution, verify the Scene overlay, Editor Play, standalone runtime,
save/reload, and the UI editor panel at:
1280x7201920x10801920x12001225x551Confirm that the preview matches runtime layout, the
64pxtest bar remainsflush with the viewport bottom, the scene remains visible behind the UI, the UI
editor preview is unchanged, and world-space canvases are unaffected.