Skip to content
Merged
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
6 changes: 4 additions & 2 deletions apps/mobile/src/apps/Camera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -221,7 +222,7 @@ function Camera({ active }: { active: boolean }) {
const drawBar = (b: Bar) => {
const v = sideways(b.edge);
return (
<View key={b.id} pointerEvents={preview ? "none" : "auto"} style={[s.bar, v ? s.barV : s.barH, b.over && s.barOver, preview && { opacity: 0.85 }, { justifyContent: JUSTIFY[b.distribution] }, b.items.some((x) => x.control === "shutter") && (v ? { minWidth: 96 } : { minHeight: 96 })]}>
<View key={b.id} pointerEvents={preview ? "none" : "auto"} style={[s.bar, v ? s.barV : s.barH, b.over && s.barOver, preview && { opacity: 0.85 }, preview && grid && s.barGrid, { justifyContent: JUSTIFY[b.distribution] }, b.items.some((x) => x.control === "shutter") && (v ? { minWidth: 96 } : { minHeight: 96 })]}>
{b.items.map((i) => control(i, v))}
</View>
);
Expand Down Expand Up @@ -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" },
Expand Down
5 changes: 3 additions & 2 deletions apps/mobile/src/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ let retry: ReturnType<typeof setTimeout> | undefined;
const channels = new Map<string, Set<(m: Msg) => 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 };
Expand Down Expand Up @@ -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 });
Expand Down
59 changes: 48 additions & 11 deletions apps/studio/src/apps/LayoutsApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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<string>(() => win.resource?.id ?? "viewfinder");
useEffect(() => { setTitle("Camera layouts"); setRoute(cur); }, [cur]);
Expand All @@ -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 <Editor key={id} id={id} file={file} layouts={layouts} devices={devices} onPick={setCur} />;
return <Editor key={id} id={id} file={file} layouts={layouts} devices={devices} onPick={setCur} projectId={projectId} />;
}

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<LayoutBody>(() => (builtin ? copyLayout(builtin.body) : (file!.body as unknown as LayoutBody)));
Expand Down Expand Up @@ -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<string>("");
const [withPreset, setWithPreset] = useState<string>("");
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";

Expand Down Expand Up @@ -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;
Expand All @@ -151,21 +161,43 @@ function Editor({ id, file, layouts, devices, onPick }: { id: string; file: File
else if (c.kind === "shutter") el = <Shutter />;
else if (i.control === "last") el = <span className="lay-last"><Icon name="image" size={20} /></span>;
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"
? <span className={cx("lay-step", vertical && "is-v")}><CameraButton icon={vertical ? "chevron-up" : "chevron-left"} label={`Previous: ${c.label}`} /><b>{now}</b><CameraButton icon={vertical ? "chevron-down" : "chevron-right"} label={`Next: ${c.label}`} /></span>
: <span className={cx("lay-strip", vertical && "is-v")}>{vals.map((v) => <CameraButton key={v} label={v} pressed={v === now}>{v}</CameraButton>)}</span>;
} else el = <span className="lay-ctl"><CameraButton icon={c.icon as IconName} label={c.label} pressed={i.control === "blackout" && body.look.blackoutOn} />{i.label && "short" in c && <small>{c.short}</small>}</span>;
// 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 <span key={i.control} data-ctl={i.control} className={cx("lay-slot", drag?.ctl === i.control && "is-dragged", off && "is-off")} title={off ? `${c.label}: needs its extension, left out on the phone` : locked ? c.label : `${c.label}: drag to move it`} onPointerDown={grab(i.control)}>{el}</span>;
return <span key={i.control} data-ctl={i.control} className={cx("lay-slot", drag?.ctl === i.control && "is-dragged", off && "is-off")} title={off ? `${c.label}: needs its extension, left out on the phone` : locked ? c.label : `${c.label}: drag to move it, click to find it in Bars, right-click to remove it`}
onPointerDown={grab(i.control)} onClick={() => findInBars(i.control)} onContextMenu={(e) => controlMenu(e, i.control)}>{el}</span>;
};
const drawBar = (b: Bar) => (
<div key={b.id} data-bar={b.id} data-axis={sideways(b.edge) ? "y" : "x"} className={cx("lay-bar", b.over && "is-over", sideways(b.edge) ? "is-v" : "is-h", `is-${b.distribution}`, b.items.some((i) => i.control === "shutter") && "has-shutter")}>
{b.items.map((i) => draw(i, sideways(b.edge)))}{!b.items.length && <small className="lay-bar__empty">{b.name}</small>}
</div>
);
/** A click on a control in the preview: its entry in Bars scrolls into view and flashes (#426). */
const panelRef = useRef<HTMLDivElement>(null);
const findInBars = (ctl: ControlId) => {
const li = panelRef.current?.closest(".oc-app")?.querySelector<HTMLElement>(`.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 && <div key={e} className={cx("lay-over", `lay-over--${e}`)}>{mine.map(drawBar)}</div>; });
const view = (
Expand All @@ -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 = (
<div className="lay-device" style={{ width: w * k + 16, height: h * k + 16 }}>
<div className={cx("lay-screen", land && "is-land")} style={{ width: w, height: h, scale: String(k) }}>
<div ref={panelRef} className={cx("lay-screen", land && "is-land", grid && "is-grid")} style={{ width: w, height: h, scale: String(k) }}>
{land ? <>{at("left")}<div className="lay-mid">{at("top")}{view}{at("bottom")}</div>{at("right")}</> : <>{at("top")}<div className="lay-mid">{at("left")}{view}{at("right")}</div>{at("bottom")}</>}
</div>
</div>
Expand Down Expand Up @@ -265,6 +297,11 @@ function Editor({ id, file, layouts, devices, onPick }: { id: string; file: File
{locked ? <strong className="st-title">{name}</strong> : <TextInput size="sm" value={name} aria-label="Name" maxLength={120} style={{ width: 200 }} onInput={(e) => setName(e.currentTarget.value)} onBlur={rename} onKeyDown={(e) => { if (e.key === "Enter") e.currentTarget.blur(); }} />}
{locked ? <Badge icon="lock">Built in, read-only</Badge> : <span className="lay-saved">{status === "invalid" ? <><Icon name="warning" size={12} />Not saved yet</> : status === "waiting" ? "Changed" : <><Icon name="check" size={12} />Saved</>}</span>}
<Segmented label="Orientation" value={key} onChange={(v) => setLand(v === "landscape")} options={[{ value: "portrait", label: "Upright" }, { value: "landscape", label: "Landscape" }]} />
<Select size="sm" aria-label="Preview as a device" value={asDevice} onChange={setAsDevice} title="Whose camera and real lenses the preview shows; for previewing only"
options={[{ value: "", label: previewing && phone?.id ? `As ${phone.name || "the device"} (live)` : body.device ? `As ${devices.find((d) => d.id === body.device)?.name ?? "its device"}` : "As a usual phone" }, ...devices.filter((d) => d.id !== body.device).map((d) => ({ value: d.id, label: `As ${d.name}` }))]} />
<Select size="sm" aria-label="Preview with an optics preset" value={withPreset} onChange={setWithPreset} title="Whose focal lengths the focal length control shows; for previewing only"
options={[{ value: "", label: "Sample focal lengths" }, ...presets.map((p) => ({ value: p.id, label: `With ${p.name}` }))]} />
<Button size="sm" variant="quiet" icon="grid" selected={grid} onClick={() => setGrid(!grid)} title="Outline every bar, here and on the device's live preview">Grid</Button>
<ToolbarSpacer />
<button type="button" className={cx("lay-pill", `is-${pillState}`)} disabled={pillState === "none" || !!wrong} title={pillState === "none" ? "Open the app on a phone signed in to this account" : previewing ? "Stop the preview on the phone" : "Show this layout on the phone while you change it"}
onClick={() => { if (previewing) { sendLink({ ch: "layout", type: "stop" }); setPreviewing(false); } else setPreviewing(true); }}><i />{pillText}</button>
Expand Down
5 changes: 5 additions & 0 deletions apps/studio/src/layouts/layouts.css
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
3 changes: 3 additions & 0 deletions docs/features/camera-layouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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), "<phone> connected", "Previewing on <phone>". 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.
Expand Down
Loading