Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

refactor(layout): give the effective-preset rule one home

EtienneLescotb7ba62503861
diff --git a/src/components/ai-edition/PreviewCanvas.tsx b/src/components/ai-edition/PreviewCanvas.tsx
index 3bf042a09..6f59e066f 100644
--- a/src/components/ai-edition/PreviewCanvas.tsx
+++ b/src/components/ai-edition/PreviewCanvas.tsx
@@ -47,6 +47,7 @@ import { locateVirtualPosition } from "@/lib/ai-edition/timeline/virtual-preview
import {
computeCameraFullscreenRect,
computeCompositeLayout,
+ resolveWebcamLayoutPreset,
type WebcamCompositeLayout,
} from "@/lib/compositeLayout";
import { classifyWallpaper, resolveImageWallpaperUrl } from "@/lib/wallpaper";
@@ -231,9 +232,10 @@ export function PreviewCanvas(props: PreviewCanvasProps) {
// A clip with no camera lays out as "no-webcam", whatever the panel says. Hiding
// only the webcam slot is not enough: the block presets size the SCREEN off the
// block, so the screen stayed squeezed into its half with nothing beside it.
- const preset = (
- activeClipHasCamera ? settings.webcamLayoutPreset : "no-webcam"
- ) as WebcamLayoutPreset;
+ const preset = resolveWebcamLayoutPreset(
+ settings.webcamLayoutPreset as WebcamLayoutPreset,
+ activeClipHasCamera,
+ );
const mask = settings.webcamMaskShape as WebcamMaskShape;
// ponytail: padding shrinks the available content area for ALL layouts
// (PiP/dual/stack) so the screen doesn't fill the canvas edge-to-edge.
diff --git a/src/components/ai-edition/RightPanes.tsx b/src/components/ai-edition/RightPanes.tsx
index 0fb1eb918..30206f587 100644
--- a/src/components/ai-edition/RightPanes.tsx
+++ b/src/components/ai-edition/RightPanes.tsx
@@ -56,7 +56,7 @@ import { formatMs } from "@/lib/ai-edition/timeline/format";
import { locateVirtualPosition } from "@/lib/ai-edition/timeline/virtual-preview";
import type { TranscriptGateReason } from "@/lib/ai-edition/transcription/status";
import { getAssetPath } from "@/lib/assetPath";
-import { supportsWebcamReactiveZoom } from "@/lib/compositeLayout";
+import { resolveWebcamLayoutPreset, supportsWebcamReactiveZoom } from "@/lib/compositeLayout";
import { supportsCursorClickEffects } from "@/lib/cursor/cursorCapabilities";
import { CURSOR_THEMES, DEFAULT_CURSOR_THEME_ID } from "@/lib/cursor/cursorThemes";
import { buildGradientFromEditor } from "@/lib/gradientBuilder";
@@ -1500,14 +1500,27 @@ export function LayoutPane() {
const ts = useScopedT("settings");
const { settings, set, setLive, commit, hasDocument } = useEditorSettings();
const document = useProjectStore((s) => s.document);
- // A project can hold clips with no camera attached at all (plain imports or
- // a recording made without a webcam). Keep the saved camera preference for
- // later, but make the disabled control describe what the preview/export
- // actually render right now.
- const hasAnyCamera = document
- ? hasAnyClipWithCamera(document.assets, document.timeline.clips)
- : false;
- const effectiveLayoutPreset = hasAnyCamera ? settings.webcamLayoutPreset : "no-webcam";
+ // A project can hold clips with no camera attached at all (plain imports or a
+ // recording made without a webcam). Keep the saved camera preference for later, but
+ // make the disabled control describe whether this project has any camera at all.
+ //
+ // The preset is global while the camera is per clip, so a MIXED project shows the
+ // saved preset here while the playhead may sit over a camera-less clip — the
+ // preview and the scene answer `hasCamera` per clip, this panel answers it for the
+ // project. Deliberately `hasAnyClipWithCamera` (is a camera attached?) and not
+ // `assetCameraSource` (attached AND visible): a hidden camera keeps its saved preset
+ // on display, because this panel is the surface you would use to un-hide it.
+ //
+ // Memoised because the pane subscribes to the whole document, and `setLive` during a
+ // slider drag replaces it every frame — this scan is O(clips x assets).
+ const hasAnyCamera = useMemo(
+ () => (document ? hasAnyClipWithCamera(document.assets, document.timeline.clips) : false),
+ [document],
+ );
+ const effectiveLayoutPreset = resolveWebcamLayoutPreset(
+ settings.webcamLayoutPreset,
+ hasAnyCamera,
+ );
// Synchro initiale : cf. NativeCompositorOverlay (`pushAllNativeParams`).
// the mask shape picker only makes sense for Picture-in-Picture.
@@ -1521,12 +1534,17 @@ export function LayoutPane() {
// as a control that does nothing.
const supportsReactiveZoom = supportsWebcamReactiveZoom(effectiveLayoutPreset);
const layoutControlsDisabled = !hasDocument || !hasAnyCamera;
+ // The controls go dead and the preset reads "No Webcam", but the saved preference is
+ // still on disk. Say so, otherwise the only signal the user gets is their setting
+ // apparently having been thrown away.
+ const helpText = hasDocument && !hasAnyCamera ? ts("layout.helpNoWebcam") : ts("layout.help");
return (
- <Pane title={ts("layout.title")} icon={<LayoutIcon size={14} />} helpText={ts("layout.help")}>
+ <Pane title={ts("layout.title")} icon={<LayoutIcon size={14} />} helpText={helpText}>
<div className={styles.sectionLabel}>{ts("layout.preset")}</div>
<div className={styles.field}>
- <label>{ts("layout.title")}</label>
+ <label htmlFor="layout-preset">{ts("layout.title")}</label>
<select
+ id="layout-preset"
value={effectiveLayoutPreset}
disabled={layoutControlsDisabled}
onChange={(e) =>
diff --git a/src/lib/compositeLayout.ts b/src/lib/compositeLayout.ts
index eaf389e90..11eb35a50 100644
--- a/src/lib/compositeLayout.ts
+++ b/src/lib/compositeLayout.ts
@@ -144,6 +144,24 @@ export function resolveWebcamReactiveZoom(
return Boolean(enabled) && supportsWebcamReactiveZoom(preset);
}
+/**
+ * Effective layout preset: the stored setting, gated by whether there is a camera to lay
+ * out at all. Without one the answer is `no-webcam` whatever the panel holds — hiding
+ * just the webcam slot is not enough, because the block presets size the SCREEN off the
+ * block and would leave it squeezed into half an empty canvas. One rule shared by the
+ * settings panel, the preview and the native scene, so the three cannot drift.
+ *
+ * `hasCamera` is the caller's question to answer, and they do not all ask it the same
+ * way on purpose: the preview and the scene resolve it per clip, while the settings
+ * panel asks whether the project has any camera at all.
+ */
+export function resolveWebcamLayoutPreset(
+ preset: WebcamLayoutPreset | undefined,
+ hasCamera: boolean,
+): WebcamLayoutPreset {
+ return hasCamera ? (preset ?? "picture-in-picture") : "no-webcam";
+}
+
export interface WebcamCompositeLayout {
screenRect: RenderRect;
webcamRect: StyledRenderRect | null;
diff --git a/src/native/sceneDescription.ts b/src/native/sceneDescription.ts
index 7186d66e5..02246f58d 100644
--- a/src/native/sceneDescription.ts
+++ b/src/native/sceneDescription.ts
@@ -35,6 +35,7 @@ import { projectRegionsToSource } from "@/lib/ai-edition/timeline/timelineMap";
import {
computeCompositeLayout,
type RenderRect,
+ resolveWebcamLayoutPreset,
resolveWebcamReactiveZoom,
webcamSizeToFraction,
} from "@/lib/compositeLayout";
@@ -586,7 +587,7 @@ export function buildSceneDescription(
* gates the camera's own draw — it cannot give the screen its frame back.
*/
const layoutForClip = (screenSize: { width: number; height: number }, hasCamera: boolean) => {
- const preset = hasCamera ? settings.webcamLayoutPreset : "no-webcam";
+ const preset = resolveWebcamLayoutPreset(settings.webcamLayoutPreset, hasCamera);
return computeCompositeLayout({
canvasSize: outputDims,
maxContentSize: {