Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-preview-scaling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@open-codesign/desktop': patch
---

Preserve preview artboard scroll bounds at scaled zoom levels to prevent desktop and tablet previews from being clipped.
10 changes: 10 additions & 0 deletions apps/desktop/src/renderer/src/components/PreviewPane.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
previewArtboardStyle,
previewPaneLayoutClasses,
previewViewportDimensions,
scaledPreviewFrameStyle,
scaleRectForZoom,
stablePreviewSourceKey,
} from './PreviewPane';
Expand Down Expand Up @@ -116,6 +117,15 @@ describe('preview artboard frame', () => {
}),
).toBe(100);
});

it('preserves scaled desktop dimensions as minimum scroll bounds', () => {
expect(scaledPreviewFrameStyle('desktop', 150)).toEqual({
width: '2160px',
height: '1350px',
minWidth: '2160px',
minHeight: '1350px',
});
});
});

describe('preview pane welcome state', () => {
Expand Down
20 changes: 13 additions & 7 deletions apps/desktop/src/renderer/src/components/PreviewPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ export function previewArtboardFrameClass(): string {
return ARTBOARD_FRAME_CLASS;
}

export function scaledPreviewFrameStyle(
viewport: PreviewSlotProps['viewport'],
zoom: number,
): CSSProperties {
const frame = previewViewportDimensions(viewport);
const scale = zoom / 100;
const width = `${Math.round(frame.width * scale)}px`;
const height = `${Math.round(frame.height * scale)}px`;

return { width, height, minWidth: width, minHeight: height };
}

function ScaledPreviewFrame({
viewport,
zoom,
Expand All @@ -179,13 +191,7 @@ function ScaledPreviewFrame({
const frame = previewViewportDimensions(viewport);
const scale = zoom / 100;
return (
<div
className="relative flex-shrink-0"
style={{
width: `${frame.width * scale}px`,
height: `${frame.height * scale}px`,
}}
>
<div className="relative flex-shrink-0" style={scaledPreviewFrameStyle(viewport, zoom)}>
<div
className="origin-top-left"
style={{
Expand Down
Loading