mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
<details> <summary>Prompts Used</summary> User: Let's speed up the default speed of the menu animation (ie, what the Normal speed setting corresponds to) by 2x. Opus 5.5: > Menu animations now run twice as fast at Normal speed. The build and typecheck passed; I haven't tried it on the glasses yet. > > I halved the two base durations that every menu animation speed is calculated from: > - **Highlight slide and list scroll:** 240ms → 120ms (`app/ui/menu-highlight-motion.ts:4`) > - **End-of-list bounce:** 320ms → 160ms (`app/ui/menu-scroll-motion.ts:8`) > > This covers menus, lists, and the launcher and Files icon grids. The other speed settings are calculated from these values, so they get twice as fast too: Slow now matches the old Normal, and Very Fast is now 24ms for the slide. The screen fade setting uses the same speed scale but its own duration, so it isn't affected. </details>
51 lines
2.6 KiB
TypeScript
51 lines
2.6 KiB
TypeScript
import { menuAnimationDurationMs } from "./menu-animation-pref";
|
|
|
|
/** At Normal menu animation speed; menuAnimationDurationMs scales it to the setting. */
|
|
export const MENU_HIGHLIGHT_DURATION_MS = 120;
|
|
export type MenuHighlightAnimation = { dx: number; dy: number; startedAt: number; token: number; durationMs: number };
|
|
|
|
let nextToken = 1;
|
|
|
|
/** A fresh display-list timeline token, shared by all menu animations. */
|
|
export function nextAnimationToken(): number {
|
|
return nextToken++;
|
|
}
|
|
|
|
/** Eligibility is decided by menu navigation, before the display-list bridge. */
|
|
export class MenuHighlightMotion {
|
|
private previous?: { index: number; scroll: number; x: number; y: number; width: number; height: number };
|
|
private fromIndex: number | null = null;
|
|
private animation?: MenuHighlightAnimation;
|
|
|
|
navigate(from: number, wrapped: boolean): void {
|
|
this.fromIndex = wrapped ? null : from;
|
|
}
|
|
|
|
/** `scrolling`: the scroll change since the last paint is itself animated, so the highlight may slide across it. */
|
|
paint(index: number, scroll: number, x: number, y: number, width: number, height: number, now: number, scrolling = false): MenuHighlightAnimation | undefined {
|
|
const previous = this.previous;
|
|
if (!previous || previous.index !== index || previous.scroll !== scroll ||
|
|
previous.x !== x || previous.y !== y || previous.width !== width || previous.height !== height) {
|
|
let fromX = previous?.x ?? x, fromY = previous?.y ?? y;
|
|
if (previous && this.animation) {
|
|
const t = Math.max(0, Math.min(1, (now - this.animation.startedAt) / this.animation.durationMs));
|
|
const remaining = 1 - t * t * (3 - 2 * t);
|
|
fromX += this.animation.dx * remaining;
|
|
fromY += this.animation.dy * remaining;
|
|
}
|
|
const durationMs = menuAnimationDurationMs(MENU_HIGHLIGHT_DURATION_MS);
|
|
const eligible = durationMs > 0 && previous && previous.index !== index && this.fromIndex === previous.index &&
|
|
(previous.scroll === scroll || scrolling) && previous.width === width && previous.height === height;
|
|
this.animation = eligible ? { dx: Math.round(fromX - x), dy: Math.round(fromY - y), startedAt: now, token: nextAnimationToken(), durationMs } : undefined;
|
|
this.fromIndex = null;
|
|
this.previous = { index, scroll, x, y, width, height };
|
|
}
|
|
return this.animation && now - this.animation.startedAt < this.animation.durationMs ? this.animation : undefined;
|
|
}
|
|
|
|
/** Cancel an animation in flight, e.g. when it cannot be drawn; the next change snaps from where it rests. */
|
|
cancel(): void {
|
|
this.animation = undefined;
|
|
}
|
|
}
|