From 116619abf1fc424c9458f8df4d1bf0f1f45486f7 Mon Sep 17 00:00:00 2001 From: bubulux Date: Wed, 25 Nov 2026 17:56:23 +0100 Subject: [PATCH] Camera layout editor: preview as a device and with a preset, layout grid, find and remove from the preview (#426) - For previewing only, never saved: As (default: the device showing the live preview, else the one the layout is designed for), With (its focal lengths in the focal length control), Grid (every bar outlined with a faint fill, also on the device's live preview). - A click on a control in the preview scrolls its entry in Bars into view and flashes it; a right-click offers Show in Bars and Remove (not the shutter). Co-Authored-By: Claude Opus 5.5 --- apps/mobile/src/apps/Camera.tsx | 6 ++- apps/mobile/src/link.ts | 5 ++- apps/studio/src/apps/LayoutsApp.tsx | 59 +++++++++++++++++++++++------ apps/studio/src/layouts/layouts.css | 5 +++ docs/features/camera-layouts.md | 3 ++ 5 files changed, 63 insertions(+), 15 deletions(-) diff --git a/apps/mobile/src/apps/Camera.tsx b/apps/mobile/src/apps/Camera.tsx index 6a13e62..826c269 100644 --- a/apps/mobile/src/apps/Camera.tsx +++ b/apps/mobile/src/apps/Camera.tsx @@ -7,7 +7,7 @@ import { CONTROLS, focalsOf, REFERENCE_STEPS, type Bar, type ControlId, type Dis import { canCall, putFile } from "../api"; import { measureCamera, useLensSet } from "../device"; import type { Lens } from "../lenses"; -import { leavePreview } from "../link"; +import { leavePreview, previewLayout } from "../link"; import { log } from "../log"; import { libraryFile, loadLibrary, useLibrary, usePresets } from "../media/library"; import { addCapture } from "../media/pipeline"; @@ -56,6 +56,7 @@ function Camera({ active }: { active: boolean }) { const presets = usePresets(); const lib = useLibrary(); const { layout, preview, orientation } = useLayout(); + const grid = !!previewLayout.use()?.grid; const body: LayoutBody = layout.body; const landscape = orientation ? orientation === "landscape" : width > height; const arrangement = landscape ? body.landscape : body.portrait; @@ -221,7 +222,7 @@ function Camera({ active }: { active: boolean }) { const drawBar = (b: Bar) => { const v = sideways(b.edge); return ( - x.control === "shutter") && (v ? { minWidth: 96 } : { minHeight: 96 })]}> + x.control === "shutter") && (v ? { minWidth: 96 } : { minHeight: 96 })]}> {b.items.map((i) => control(i, v))} ); @@ -449,6 +450,7 @@ const useStyles = makeStyles(() => ({ strip: { flexDirection: "row", gap: 8, alignItems: "center" }, stripV: { flexDirection: "column" }, stepped: { flexDirection: "row", alignItems: "center", gap: 4, padding: 3, borderRadius: 28, borderWidth: 2, borderColor: FIXED.white, backgroundColor: FIXED.black }, + barGrid: { borderWidth: 1, borderStyle: "dashed", borderColor: FIXED.white, backgroundColor: FIXED.glass }, zoom: { flexDirection: "row", alignItems: "center", padding: 4, borderRadius: 28, backgroundColor: FIXED.black, borderWidth: 2, borderColor: FIXED.white }, zoomV: { flexDirection: "column" }, zoomTrack: { position: "relative" }, diff --git a/apps/mobile/src/link.ts b/apps/mobile/src/link.ts index 0e84ccf..740d92e 100644 --- a/apps/mobile/src/link.ts +++ b/apps/mobile/src/link.ts @@ -20,7 +20,8 @@ let retry: ReturnType | undefined; const channels = new Map void>>(); /** A camera layout the Studio shows on this phone while it is changed there; nothing is saved. */ -export const previewLayout = persisted<{ layout: unknown; orientation: "portrait" | "landscape" } | null>("linkPreview.v1", null); +/** The Studio's live preview of a layout; `grid`: every bar outlined, as the Studio's layout grid (#426). */ +export const previewLayout = persisted<{ layout: unknown; orientation: "portrait" | "landscape"; grid?: boolean } | null>("linkPreview.v1", null); /** Whether the link is open, and how many Studio tabs are (as the room last said; null: not heard yet). */ let status: { open: boolean; studios: number | null } = { open: false, studios: null }; @@ -60,7 +61,7 @@ function open() { s.onmessage = (e) => { let m: Msg; try { m = JSON.parse(String(e.data)) as Msg; } catch { return; } - if (m.ch === "layout" && m.type === "preview") previewLayout.set({ layout: m.layout, orientation: m.orientation === "landscape" ? "landscape" : "portrait" }); + if (m.ch === "layout" && m.type === "preview") previewLayout.set({ layout: m.layout, orientation: m.orientation === "landscape" ? "landscape" : "portrait", grid: m.grid === true }); else if (m.ch === "layout" && m.type === "stop") previewLayout.set(null); else if (m.ch === "link" && m.type === "readout") void syncDevice().then(hello); else if (m.ch === "link" && m.type === "presence") setStatus({ studios: typeof m.studios === "number" ? m.studios : null }); diff --git a/apps/studio/src/apps/LayoutsApp.tsx b/apps/studio/src/apps/LayoutsApp.tsx index 3218983..ca72a5c 100644 --- a/apps/studio/src/apps/LayoutsApp.tsx +++ b/apps/studio/src/apps/LayoutsApp.tsx @@ -12,12 +12,13 @@ import { } from "@openclapper/design"; import { BLACKOUT_TINTS, BUILTIN_LAYOUTS, CONTROLS, FRAME_COLOURS, FRAME_WIDTHS, REFERENCE_STEPS, copyLayout, isBuiltinLayout, layoutError, unplaced, - type Bar, type ControlId, type Distribution, type Edge, type LayoutBody, type LayoutItem, + focalsOf, type Bar, type ControlId, type Distribution, type Edge, type LayoutBody, type LayoutItem, } from "@openclapper/model"; +import { presetsIn } from "../optics"; import * as api from "../api"; import type { FileRec } from "../api"; import * as store from "../files"; -import { confirm, toastError } from "../hosts"; +import { confirm, contextMenu, toastError } from "../hosts"; import { sendLink, usePhoneLink } from "../phoneLink"; import { activeExtensions, extensionOn, type AppProps } from "./registry"; @@ -30,7 +31,7 @@ const SAMPLE_FOCALS = ["24", "35", "50", "85"]; const sideways = (e: Edge) => e === "left" || e === "right"; interface DeviceBody { lenses?: { id: string; name: string; focal35: number | null; main?: boolean }[]; camera?: { portrait: { w: number; h: number }; landscape: { w: number; h: number } } | null; screen?: { portrait: { w: number; h: number }; landscape: { w: number; h: number } } | null; layout?: string } -export function LayoutsApp({ win, setTitle, setRoute }: AppProps) { +export function LayoutsApp({ win, projectId, setTitle, setRoute }: AppProps) { const { files } = store.useRoot("home"); const [cur, setCur] = useState(() => win.resource?.id ?? "viewfinder"); useEffect(() => { setTitle("Camera layouts"); setRoute(cur); }, [cur]); @@ -39,10 +40,10 @@ export function LayoutsApp({ win, setTitle, setRoute }: AppProps) { const devices = files.filter((f) => f.type === "device"); const file = isBuiltinLayout(cur) ? null : layouts.find((l) => l.id === cur) ?? null; const id = isBuiltinLayout(cur) || file ? cur : "viewfinder"; - return ; + return ; } -function Editor({ id, file, layouts, devices, onPick }: { id: string; file: FileRec | null; layouts: FileRec[]; devices: FileRec[]; onPick: (id: string) => void }) { +function Editor({ id, file, layouts, devices, onPick, projectId }: { id: string; file: FileRec | null; layouts: FileRec[]; devices: FileRec[]; onPick: (id: string) => void; projectId: string }) { const builtin = isBuiltinLayout(id) ? BUILTIN_LAYOUTS[id] : null; const locked = !!builtin; const [body, setBody] = useState(() => (builtin ? copyLayout(builtin.body) : (file!.body as unknown as LayoutBody))); @@ -81,9 +82,14 @@ function Editor({ id, file, layouts, devices, onPick }: { id: string; file: File // The live preview: while the Studio previews, every change goes to the phone. const [previewing, setPreviewing] = useState(false); const phone = link.phones[0]; - const preview = () => sendLink({ ch: "layout", type: "preview", layout: latest.current, orientation: key, device: body.device }); + // For previewing only, never part of the layout (#426): which device's camera and lenses, which optics preset's + // focal lengths, and the grid that outlines every bar (also on the device's live preview). + const [asDevice, setAsDevice] = useState(""); + const [withPreset, setWithPreset] = useState(""); + const [grid, setGrid] = useState(false); + const preview = () => sendLink({ ch: "layout", type: "preview", layout: latest.current, orientation: key, device: body.device, grid }); useEffect(() => { if (!link.previewing && previewing) setPreviewing(false); }, [link.previewing]); - useEffect(() => { if (previewing && !wrong) preview(); }, [previewing, body, key]); + useEffect(() => { if (previewing && !wrong) preview(); }, [previewing, body, key, grid]); useEffect(() => () => { if (previewing) sendLink({ ch: "layout", type: "stop" }); }, [previewing]); const pillState = !link.open || !link.phones.length ? "none" : previewing ? "preview" : "connected"; @@ -132,7 +138,11 @@ function Editor({ id, file, layouts, devices, onPick }: { id: string; file: File }; // ---------- The preview: the device's camera with the bars around the picture ---------- - const dev = devices.find((d) => d.id === body.device); + // The device shown: the one picked for the preview, else the one showing the live preview, else the one the layout is designed for. + const dev = devices.find((d) => d.id === (asDevice || (previewing ? phone?.id : null) || body.device)); + const project = store.useRoot({ project: projectId }); + const presets = presetsIn(project.files ?? []); + const preset = presets.find((p) => p.id === withPreset); const db = (dev?.body ?? {}) as DeviceBody; const area = db.camera ?? db.screen ?? GENERIC; const { w, h } = land ? area.landscape : area.portrait; @@ -151,7 +161,8 @@ function Editor({ id, file, layouts, devices, onPick }: { id: string; file: File else if (c.kind === "shutter") el = ; else if (i.control === "last") el = ; else if (c.kind === "strip") { - const vals = i.control === "lenses" ? lenses : SAMPLE_FOCALS, now = vals[Math.min(1, vals.length - 1)] ?? "–"; + const focals = preset ? focalsOf(preset.body.lenses).map(String) : SAMPLE_FOCALS; + const vals = i.control === "lenses" ? lenses : focals, now = vals[Math.min(1, vals.length - 1)] ?? "–"; // Stepped: three full-size parts a thumb can hit, back, the value, on; stacked in an upright bar. el = i.display === "stepped" ? {now} @@ -159,13 +170,34 @@ function Editor({ id, file, layouts, devices, onPick }: { id: string; file: File } else el = {i.label && "short" in c && {c.short}}; // An extension's control while the project has it off: kept in the layout, greyed here, left out on the phone. const off = !extensionOn(c.extension); - return {el}; + return findInBars(i.control)} onContextMenu={(e) => controlMenu(e, i.control)}>{el}; }; const drawBar = (b: Bar) => (
i.control === "shutter") && "has-shutter")}> {b.items.map((i) => draw(i, sideways(b.edge)))}{!b.items.length && {b.name}}
); + /** A click on a control in the preview: its entry in Bars scrolls into view and flashes (#426). */ + const panelRef = useRef(null); + const findInBars = (ctl: ControlId) => { + const li = panelRef.current?.closest(".oc-app")?.querySelector(`.lay-items [data-ctl="${ctl}"]`); + if (!li) return; + li.scrollIntoView({ block: "center", behavior: "smooth" }); + li.classList.remove("is-flash"); + void li.offsetWidth; + li.classList.add("is-flash"); + }; + /** Right-click on a control in the preview: remove it, or find it in Bars (#426). */ + const controlMenu = (e: MouseEvent, ctl: ControlId) => { + e.preventDefault(); + const bar = bars.find((b) => b.items.some((i) => i.control === ctl)); + contextMenu(e, [ + { heading: CONTROLS[ctl].label }, + { id: "find", label: "Show in Bars", icon: "search", run: () => findInBars(ctl) }, + { id: "remove", label: ctl === "shutter" ? "The shutter cannot be removed" : "Remove", icon: "trash", danger: true, disabled: locked || ctl === "shutter" || !bar, run: () => bar && patchBar(bar.id, { items: bar.items.filter((y) => y.control !== ctl) }) }, + ]); + }; const at = (e: Edge) => bars.filter((b) => b.edge === e && !b.over).map(drawBar); const over = EDGES.map(([e]) => { const mine = bars.filter((b) => b.edge === e && b.over); return mine.length > 0 &&
{mine.map(drawBar)}
; }); const view = ( @@ -178,7 +210,7 @@ function Editor({ id, file, layouts, devices, onPick }: { id: string; file: File // Upright, top and bottom bars take the full width and the side bars the height left between them; in landscape the other way round. const shown = (
-
+
{land ? <>{at("left")}
{at("top")}{view}{at("bottom")}
{at("right")} : <>{at("top")}
{at("left")}{view}{at("right")}
{at("bottom")}}
@@ -265,6 +297,11 @@ function Editor({ id, file, layouts, devices, onPick }: { id: string; file: File {locked ? {name} : setName(e.currentTarget.value)} onBlur={rename} onKeyDown={(e) => { if (e.key === "Enter") e.currentTarget.blur(); }} />} {locked ? Built in, read-only : {status === "invalid" ? <>Not saved yet : status === "waiting" ? "Changed" : <>Saved}} setLand(v === "landscape")} options={[{ value: "portrait", label: "Upright" }, { value: "landscape", label: "Landscape" }]} /> + ({ value: p.id, label: `With ${p.name}` }))]} /> + diff --git a/apps/studio/src/layouts/layouts.css b/apps/studio/src/layouts/layouts.css index 9fcb843..b0b5422 100644 --- a/apps/studio/src/layouts/layouts.css +++ b/apps/studio/src/layouts/layouts.css @@ -85,3 +85,8 @@ /* An extension's control while the project has it off. */ .lay-slot.is-off { opacity: .4; filter: grayscale(1); } .lay-item__name small { color: var(--text-secondary); } +/* The layout grid (#426): every bar outlined with a faint fill, to see what each one takes. */ +.lay-screen.is-grid .lay-bar { outline: 1px dashed var(--accent); outline-offset: -1px; background-color: color-mix(in srgb, var(--accent) 14%, transparent); } +/* A control found from the preview flashes in Bars (#426). */ +@keyframes lay-flash { 0%, 60% { background: var(--marquee); box-shadow: inset 0 0 0 2px var(--accent); } 100% { background: transparent; box-shadow: none; } } +.lay-item.is-flash { animation: lay-flash 1.4s ease-out; } diff --git a/docs/features/camera-layouts.md b/docs/features/camera-layouts.md index 8a22822..e1e3377 100644 --- a/docs/features/camera-layouts.md +++ b/docs/features/camera-layouts.md @@ -57,6 +57,9 @@ One connection between a person's Studio tabs and their phones and tablets: `GET - **Saving**: 0.6 s after the last change, and only while the layout is valid; until then a banner says what is missing ("Not saved yet"). - **The phone link pill**: no phone (or the link offline), " connected", "Previewing on ". A click starts the live preview: the phone shows the layout as it is changed, in the orientation shown; a click again, closing the app or the phone leaving the preview ends it. Nothing is saved on the phone. +- **For previewing only** (#426, never saved in the layout): *As …* picks whose camera and real lenses the preview shows (default: the device showing the live preview, else the one the layout is designed for, else a usual phone; switched-off lenses are left out); *With …* picks an optics preset whose focal lengths the focal length control shows (to see early whether many primes fit a strip); **Grid** outlines every bar with a faint fill, here and on the device's live preview. +- **From the preview**: a click on a control scrolls its entry in Bars into view and flashes it; a right-click offers *Show in Bars* and *Remove* (not the shutter). + ## The camera on the phone (`apps/mobile/src/apps/Camera.tsx`, `src/camera/`, `src/link.ts`) - **The layout in use**: the device's choice (`device.layout`, chosen with the Layout control or in Setup, or set from the Studio), else the Viewfinder; the account's layouts are kept on the phone (loaded with each sync) so the camera opens with them offline. A layout the Studio previews takes its place meanwhile: its bars are dimmed and do nothing, the shutter is off, a chip "Studio preview · buttons off · tap to leave" ends it. A preview never outlives the link.