@remotion/studio: Add padding when fitting compositions - #9339
Merged
Conversation
Contributor
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — This PR adds a 16px screen-space gutter around compositions when Remotion Studio's preview size is set to Fit, while leaving asset previews and explicit zoom levels unchanged.
- Adds
packages/studio/src/helpers/studio-fit-padding.ts— New utilities (calculateStudioScale,calculateStudioCanvasTransformation,getStudioPaddedCanvasSize) compute the padded canvas size and apply the padding as a translation for auto-fit positioning. - Threads
addFitPaddingthroughCanvas.tsxandget-effective-translation.ts— All scale computations for compositions now use the padded canvas size, including zoom gestures, drop positioning, and zoom-in/zoom-out actions. - Updates
Preview.tsxanduse-studio-canvas-dimensions.ts— Rendering and overlay dimensions use the padded transformation, while non-composition content keeps the originalPlayerInternalsbehavior. - Provides padded canvas size via
Editor.tsxCurrentScaleContext —useCurrentScale()now reports the same padded fit scale as the visual preview. - Adds unit tests —
studio-fit-padding.test.tscovers width-constrained, height-constrained, and explicit-zoom cases.
Kimi K2 (free via Pullfrog for OSS) | 𝕏
Contributor
There was a problem hiding this comment.
✅ No new issues in the new commit.
Reviewed changes since last review — The follow-up commit "@remotion/studio: Fix asymmetric Fit padding" separates the full layout canvas size from the padded canvas size used only for auto-fit scale calculations in useCurrentScale().
- Adds
InternalCurrentScaleContextTypeinpackages/core/src/use-current-scale.ts— Extends the internal'canvas-size'context withcanvasSizeForAutoso the layout bounds remain the actual container size while auto-fit scale uses the padded bounds. - Updates
useCurrentScale()to readcanvasSizeForAuto— Auto-fit now respects the 16px Studio gutter; explicit zoom levels still ignore canvas size and return the numeric zoom. - Adds
getStudioCurrentScaleContext()inpackages/studio/src/helpers/studio-fit-padding.ts— Studio'sCurrentScaleContext.Providernow supplies both sizes without leaking the padding into layout math. - Updates
Editor.tsx— Replaces the unconditional paddedcanvasSizevalue withgetStudioCurrentScaleContext(size). - Adds a test for size separation —
keeps the layout size separate from the auto-fit sizeverifies thatcanvasSizestays at the full container size whilecanvasSizeForAutoreflects the padding.
Kimi K2 (free via Pullfrog for OSS) | 𝕏
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
useCurrentScale()Testing
bun test packages/studio/src/test/studio-fit-padding.test.tsbun run buildbun run stylecheckCloses #9337