Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Photos: whole photos in their own shape, as icloud.com's grid toggle shows them

Yashwanth Kamireddi4c65b7153b4c
diff --git a/.uiverify/photos-drag.mjs b/.uiverify/photos-drag.mjs
index 8158c5b..54748f4 100644
--- a/.uiverify/photos-drag.mjs
+++ b/.uiverify/photos-drag.mjs
@@ -33,6 +33,8 @@ const row = await trips.boundingBox();
await page.mouse.move(tile.x + 20, tile.y + 20);
await page.mouse.down();
await page.mouse.move(row.x + 30, row.y + row.height / 2, { steps: 8 });
+// Resting over the row a moment, as a hand does: the engine reports the pointer over it.
+await page.mouse.move(row.x + 40, row.y + row.height / 2, { steps: 3 });
await page.waitForTimeout(100);
const lit = await trips.getAttribute("data-drop");
await page.mouse.up();
diff --git a/.uiverify/photos-fit.mjs b/.uiverify/photos-fit.mjs
new file mode 100644
index 0000000..f86eeb3
--- /dev/null
+++ b/.uiverify/photos-fit.mjs
@@ -0,0 +1,38 @@
+// Whole photos, as icloud.com's toggle shows them: each in its own shape inside its cell, with
+// the badges and the selection on the photo itself; the choice kept after a reload; squares again.
+import { engine } from "./engine.mjs";
+import { SERVICES, installStub, openScreen } from "./stub.mjs";
+const b = await engine.launch();
+const ctx = await b.newContext({ viewport: { width: 1280, height: 800 } });
+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null });
+const page = await ctx.newPage();
+page.on("pageerror", (e) => { console.log(`FAIL page error: ${e.message}`); process.exitCode = 1; });
+await page.goto("http://localhost:4173", { waitUntil: "networkidle" });
+await openScreen(page, "Photos");
+await page.waitForTimeout(400);
+let failures = 0;
+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${m}`); if (!p) failures++; };
+const shape = () => page.locator(".px-tile").nth(1).evaluate((t) => {
+ const cell = t.getBoundingClientRect(), pic = t.querySelector(".px-pic").getBoundingClientRect();
+ return { ratio: pic.height / pic.width, fills: Math.abs(pic.height - cell.height) < 1 };
+});
+
+ok((await shape()).fills, "squares fill each cell");
+await page.getByRole("button", { name: "Show Whole Photos" }).click();
+await page.waitForTimeout(150);
+const s = await shape();
+ok(Math.abs(s.ratio - 0.75) < 0.02 && !s.fills, `whole photos keep their own shape (${s.ratio.toFixed(2)}, a 4:3 photo)`);
+ok((await page.getByRole("button", { name: "Show Square Photos" }).getAttribute("aria-pressed")) === "true", "and the toggle shows it is on");
+await page.locator(".px-tile").nth(1).click();
+await page.waitForTimeout(250);
+const frame = await page.locator(".px-tile").nth(1).locator(".px-pic").evaluate((p) => getComputedStyle(p, "::after").opacity);
+ok(frame === "1", "the selection is drawn on the photo itself");
+await page.reload({ waitUntil: "networkidle" });
+await openScreen(page, "Photos");
+await page.waitForTimeout(400);
+ok(Math.abs((await shape()).ratio - 0.75) < 0.02, "whole photos are kept after a reload");
+await page.getByRole("button", { name: "Show Square Photos" }).click();
+await page.waitForTimeout(150);
+ok((await shape()).fills, "and squares again at a click");
+await b.close();
+process.exitCode = failures ? 1 : (process.exitCode ?? 0);
diff --git a/.uiverify/photos-scale.mjs b/.uiverify/photos-scale.mjs
index 28a12ec..c05c68b 100644
--- a/.uiverify/photos-scale.mjs
+++ b/.uiverify/photos-scale.mjs
@@ -34,6 +34,22 @@ const sizes = await page.evaluate(async () => {
ok(sizes.built && Math.abs(sizes.before - sizes.after) < 1,
`a month is as tall before it is built as after ${sizes.before.toFixed(1)} → ${sizes.after.toFixed(1)}px`);
+// The same with whole photos, whose rows sit further apart.
+await page.locator(".px-scroll").evaluate((e) => (e.scrollTop = 0));
+await page.getByRole("button", { name: "Show Whole Photos" }).click();
+await page.waitForTimeout(400);
+const fitted = await page.evaluate(async () => {
+ const months = [...document.querySelectorAll(".px-month")];
+ const later = months.find((s) => s.querySelector(".px-later"));
+ const before = later.getBoundingClientRect().height;
+ later.scrollIntoView();
+ await new Promise((r) => setTimeout(r, 400));
+ return { before, after: later.getBoundingClientRect().height, built: !later.querySelector(".px-later") };
+});
+ok(fitted.built && Math.abs(fitted.before - fitted.after) < 1,
+ `with whole photos too ${fitted.before.toFixed(1)} → ${fitted.after.toFixed(1)}px`);
+await page.getByRole("button", { name: "Show Square Photos" }).click();
+await page.waitForTimeout(200);
await page.locator(".px-scroll").evaluate((e) => (e.scrollTop = 0));
await page.waitForTimeout(300);
const ms = await page.evaluate(async () => {
diff --git a/check.sh b/check.sh
index 57ab059..a5d540d 100755
--- a/check.sh
+++ b/check.sh
@@ -63,6 +63,7 @@ step "photos sort" node .uiverify/photos-sort.mjs
step "slideshow" node .uiverify/photos-show.mjs
step "photo captions" node .uiverify/photos-caption.mjs
step "photos real faults" node .uiverify/photos-real.mjs
+step "whole photos" node .uiverify/photos-fit.mjs
step "notes delete" node .uiverify/notes-delete.mjs
step "empty today" node .uiverify/reminders-empty.mjs
step "calendar keys" node .uiverify/calendar-keys.mjs
@@ -109,6 +110,7 @@ step "webkit: sort" env ENGINE=webkit node .uiverify/photos-sort.mjs
step "webkit: slideshow" env ENGINE=webkit node .uiverify/photos-show.mjs
step "webkit: captions" env ENGINE=webkit node .uiverify/photos-caption.mjs
step "webkit: real faults" env ENGINE=webkit node .uiverify/photos-real.mjs
+step "webkit: whole photos" env ENGINE=webkit node .uiverify/photos-fit.mjs
step "webkit: delete" env ENGINE=webkit node .uiverify/notes-delete.mjs
step "webkit: row hover" env ENGINE=webkit node .uiverify/row-hover.mjs
step "webkit: fold" env ENGINE=webkit node .uiverify/sidebar-fold.mjs
diff --git a/src/screens/PhotosView.tsx b/src/screens/PhotosView.tsx
index 5b7464e..fd58d41 100644
--- a/src/screens/PhotosView.tsx
+++ b/src/screens/PhotosView.tsx
@@ -7,7 +7,7 @@ import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useStat
import { listen } from "@tauri-apps/api/event";
import { getCurrentWebview } from "@tauri-apps/api/webview";
import { open as openFileDialog } from "@tauri-apps/plugin-dialog";
-import { ChevronLeft, ChevronRight, CopyMinus, CopyPlus, Download, Clock, Heart, ImagePlus, Images, Info, Minus, Play, Plus, RotateCcw, Scan, Trash2, EyeOff, ArrowDownUp, MonitorPlay, Video, X, type LucideIcon } from "lucide-react";
+import { ChevronLeft, ChevronRight, CopyMinus, CopyPlus, Download, Clock, Heart, ImagePlus, Images, Info, Minus, Play, Plus, RotateCcw, Scan, Trash2, EyeOff, ArrowDownUp, MonitorPlay, Square, RectangleHorizontal, Video, X, type LucideIcon } from "lucide-react";
import {
api,
messageOf,
@@ -101,6 +101,12 @@ const clock = (s: number | null) => {
return `${m}:${String(Math.round(s % 60)).padStart(2, "0")}`;
};
+/** A photo's frame when fitted: its own shape, as large as the square cell lets it be. */
+const fitFrame = (p: Photo): React.CSSProperties =>
+ p.width >= p.height
+ ? { width: "100%", height: `${(100 * p.height) / p.width}%` }
+ : { height: "100%", width: `${(100 * p.width) / p.height}%` };
+
/** What a tile can ask of the screen; one object, kept the same, so tiles need not redraw. */
type Acts = {
pick: (index: number, e: React.MouseEvent) => void;
@@ -121,6 +127,7 @@ const Tile = memo(function Tile({
tabbable,
left,
soon,
+ fit,
act,
}: {
photo: Photo;
@@ -129,6 +136,7 @@ const Tile = memo(function Tile({
tabbable: boolean;
left: string | null;
soon: boolean;
+ fit: boolean;
act: Acts;
}) {
return (
@@ -156,15 +164,19 @@ const Tile = memo(function Tile({
act.menu(photo, e);
}}
>
- <img src={pictureSrc(photo.id, "thumb")} alt="" loading="lazy" decoding="async" draggable={false} />
- {photo.kind === "video" && (
- <span className="px-badge px-duration">
- <Play size={10} strokeWidth={0} fill="currentColor" aria-hidden="true" />
- {clock(photo.duration)}
- </span>
- )}
- {left && <span className={`px-badge px-left${soon ? " is-soon" : ""}`}>{left}</span>}
- {photo.favorite && <Heart className="px-heart" size={13} strokeWidth={0} fill="currentColor" aria-label="Favorite" />}
+ {/* The picture's own frame: the whole tile when squares, the photo's own shape when
+ fitted — what the badges and the selection sit on. */}
+ <span className="px-pic" style={fit && photo.width && photo.height ? fitFrame(photo) : undefined}>
+ <img src={pictureSrc(photo.id, "thumb")} alt="" loading="lazy" decoding="async" draggable={false} />
+ {photo.kind === "video" && (
+ <span className="px-badge px-duration">
+ <Play size={10} strokeWidth={0} fill="currentColor" aria-hidden="true" />
+ {clock(photo.duration)}
+ </span>
+ )}
+ {left && <span className={`px-badge px-left${soon ? " is-soon" : ""}`}>{left}</span>}
+ {photo.favorite && <Heart className="px-heart" size={13} strokeWidth={0} fill="currentColor" aria-label="Favorite" />}
+ </span>
</button>
);
});
@@ -182,6 +194,7 @@ const Month = memo(function Month({
deleted,
eager,
across,
+ fit,
act,
}: {
label: string;
@@ -191,6 +204,7 @@ const Month = memo(function Month({
deleted: boolean;
eager: boolean;
across: number;
+ fit: boolean;
act: Acts;
}) {
const ref = useRef<HTMLElement | null>(null);
@@ -224,6 +238,7 @@ const Month = memo(function Month({
tabbable={anchor === index || (anchor === null && index === 0)}
left={t?.words ?? null}
soon={t?.soon ?? false}
+ fit={fit}
act={act}
/>
);
@@ -247,6 +262,24 @@ export function PhotosView() {
const [counts, setCounts] = useState<Partial<Record<PhotoView, number>>>({});
const [error, setError] = useState<string | null>(null);
const [zoom, setZoom] = useState(1);
+ // Squares that fill each cell, or each photo whole in its own shape — icloud.com's toggle,
+ // kept on this machine.
+ const [fit, setFit] = useState(() => {
+ try {
+ return window.localStorage.getItem("quince.photos.fit") === "1";
+ } catch {
+ return false;
+ }
+ });
+ const toggleFit = () =>
+ setFit((f) => {
+ try {
+ window.localStorage.setItem("quince.photos.fit", f ? "0" : "1");
+ } catch {
+ // For this run only.
+ }
+ return !f;
+ });
const [open, setOpen] = useState<number | null>(null);
const [info, setInfo] = useState(false);
const [saved, setSaved] = useState<string | null>(null);
@@ -945,8 +978,11 @@ export function PhotosView() {
if (dropOn !== a.id) setDropOn(a.id);
},
onDragLeave: (e: React.DragEvent) => {
- // Passing over the row's own symbol or name is not leaving it.
+ // Passing over the row's own symbol or name is not leaving it. Where the engine does not
+ // say where the pointer went, the row's own bounds do.
if (e.currentTarget.contains(e.relatedTarget as Node | null)) return;
+ const box = e.currentTarget.getBoundingClientRect();
+ if (e.clientX > box.left && e.clientX < box.right && e.clientY > box.top && e.clientY < box.bottom) return;
setDropOn((d) => (d === a.id ? null : d));
},
onDrop: (e: React.DragEvent) => {
@@ -1318,6 +1354,17 @@ export function PhotosView() {
)}
</div>
)}
+ <div className="px-capsule">
+ <button
+ className="px-cap"
+ aria-label={fit ? "Show Square Photos" : "Show Whole Photos"}
+ aria-pressed={fit}
+ title={fit ? "Square photos" : "Whole photos"}
+ onClick={toggleFit}
+ >
+ {fit ? <Square size={15} strokeWidth={1.9} aria-hidden="true" /> : <RectangleHorizontal size={16} strokeWidth={1.9} aria-hidden="true" />}
+ </button>
+ </div>
{sort && (
<div className="px-capsule">
<button
@@ -1383,7 +1430,7 @@ export function PhotosView() {
onClick={(e) => {
// A click on the space between photos lets the selection go, as in Photos.
if (!(e.target as HTMLElement).closest(".px-tile")) setChosen(new Set());
- }} style={{ "--across": across } as React.CSSProperties}>
+ }} data-fit={fit || undefined} style={{ "--across": across } as React.CSSProperties}>
{months.map((m, k) => (
<Month
key={`${view}/${album?.id ?? ""}/${k}/${m.label}`}
@@ -1394,6 +1441,7 @@ export function PhotosView() {
deleted={view === "recentlyDeleted" && !album}
eager={k < 3}
across={across}
+ fit={fit}
act={act}
/>
))}
diff --git a/src/styles/photos.css b/src/styles/photos.css
index 2ac1c3b..298b1a4 100644
--- a/src/styles/photos.css
+++ b/src/styles/photos.css
@@ -240,9 +240,18 @@
overflow: hidden;
cursor: default;
}
-.px-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
+.px-tile { display: grid; place-items: center; }
+/* The picture's frame: the whole cell as a square, the photo's own shape when fitted. */
+.px-pic { position: relative; display: block; width: 100%; height: 100%; overflow: hidden; }
+.px-pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
+/* Whole photos, as icloud.com shows them: each in its own shape, with room around it. */
+.px-scroll[data-fit] .px-grid { gap: 14px; padding: 0 14px; }
+.px-scroll[data-fit] .px-later { column-gap: 14px; padding: 0 14px; }
+.px-scroll[data-fit] .px-later::before { margin-bottom: calc((var(--rows) - 1) * 14px); }
+.px-scroll[data-fit] .px-tile { background: transparent; overflow: visible; }
+.px-scroll[data-fit] .px-pic { background: color-mix(in srgb, var(--text) 7%, transparent); }
/* Selected, as Photos marks it: an accent frame drawn inside the photo, over the picture. */
-.px-tile::after {
+.px-pic::after {
content: "";
position: absolute;
inset: 0;
@@ -251,10 +260,10 @@
pointer-events: none;
transition: opacity 90ms ease;
}
-.px-tile[aria-selected="true"]::after { opacity: 1; }
+.px-tile[aria-selected="true"] .px-pic::after { opacity: 1; }
.px-tile:focus-visible { outline: none; }
-.px-tile:focus-visible::after { opacity: 1; border-color: var(--accent-ring); }
-.px-tile[aria-selected="true"]:focus-visible::after { border-color: var(--accent); }
+.px-tile:focus-visible .px-pic::after { opacity: 1; border-color: var(--accent-ring); }
+.px-tile[aria-selected="true"]:focus-visible .px-pic::after { border-color: var(--accent); }
.px-badge {
position: absolute;
right: 6px;