Animations have a speed setting rather than an on/off toggle

This commit is contained in:
James Babcock committed 2026-10-03 14:40:52 -07:00
1 parent 682a8e964d
commit 9b0bf77d79
15 files changed
+110 -45

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
/**
* Speeds offered by the Settings > Customization > Animations settings.
* Animation durations are tuned at Normal; the other speeds play them faster
* or slower, and Disabled makes them instant.
*/
export const ANIMATION_SPEEDS = ["disabled", "very-fast", "fast", "normal", "slow"] as const;
export type AnimationSpeed = typeof ANIMATION_SPEEDS[number];
const SPEED_FACTORS: Record<AnimationSpeed, number> = { disabled: 0, "very-fast": 5, fast: 2, normal: 1, slow: 0.5 };
const SPEED_LABELS: Record<AnimationSpeed, string> = {
disabled: "Disabled", "very-fast": "Very Fast", fast: "Fast", normal: "Normal", slow: "Slow",
};
export function animationSpeedLabel(speed: AnimationSpeed): string {
return SPEED_LABELS[speed];
}
export function normalizeAnimationSpeed(value: string | null | undefined): AnimationSpeed {
return ANIMATION_SPEEDS.includes(value as AnimationSpeed) ? value as AnimationSpeed : "normal";
}
/** A duration tuned for Normal speed, played at `speed`: whole milliseconds, or 0 when disabled. */
export function scaleAnimationDuration(normalMs: number, speed: AnimationSpeed): number {
const factor = SPEED_FACTORS[speed];
return factor ? Math.max(1, Math.round(normalMs / factor)) : 0;
}
+14 -8
View File
@@ -18,6 +18,7 @@ import {
} from "~/assistant/models";
import { isLocalModelReady } from "../native/llama";
import { drawRightValueMenuItem, drawToggleMenuItem, MenuItem, openModalMenu } from "./menu";
import { ANIMATION_SPEEDS, animationSpeedLabel, scaleAnimationDuration, type AnimationSpeed } from "./animation-speed";
import { MENU_ANIMATION_KEY } from "./menu-animation-pref";
import { LIST_ROW_TEXT_INSET, lineStep } from "./metrics";
import { Layer, type LayerContext } from "./layers";
@@ -480,29 +481,34 @@ export const autoBrightnessCurveSetting = new ConfigSettingString({
defaultValue: DEFAULT_BRIGHTNESS_CURVE, normalize: normalizeBrightnessCurve, validate: brightnessCurveError,
description: "2–16 lux:percent pairs, separated by commas. Percent is within your minimum–maximum range. Start at 0:0, end at 100%, and increase lux without decreasing percent. Incomplete edits stay in the preview; brightness keeps using the last valid curve.",
});
/** The screen on/off fade at Normal speed. */
const SCREEN_FADE_MS = 280;
export const menuAnimationSetting = new ConfigSettingBoolean({
export const menuAnimationSetting = new ConfigSettingEnum<AnimationSpeed>({
id: "menu-animation",
label: "Menu animation",
storageKey: MENU_ANIMATION_KEY,
defaultValue: true,
description: "Slide the highlight, scroll, and bounce at the ends in menus, lists, and the launcher and Files icon grids. When off, they move instantly.",
defaultValue: "normal",
values: ANIMATION_SPEEDS,
formatValue: animationSpeedLabel,
description: "How fast the highlight slides, lists scroll, and the ends bounce in menus, lists, and the launcher and Files icon grids. Disabled moves them instantly.",
});
export const screenFadeSetting = new ConfigSettingBoolean({
export const screenFadeSetting = new ConfigSettingEnum<AnimationSpeed>({
id: "screen-fade",
label: "Screen fade",
storageKey: "display.screenFade",
defaultValue: true,
description: "Fade the display in and out when the screen turns on or off. When off, it switches instantly.",
storageKey: "display.screenFadeSpeed",
defaultValue: "normal",
values: ANIMATION_SPEEDS,
formatValue: animationSpeedLabel,
description: "How fast the display fades in and out when the screen turns on or off. Disabled switches it instantly.",
});
export function getBrightnessPreferences() {
const level = brightnessSettingToLevel(brightnessSetting.get());
return { auto: level === null, level: level ?? 50,
minimum: Number(autoBrightnessMinSetting.get()), maximum: Number(autoBrightnessMaxSetting.get()),
curve: autoBrightnessCurveSetting.getValidValue(), fadeMs: screenFadeSetting.get() ? SCREEN_FADE_MS : 0 };
curve: autoBrightnessCurveSetting.getValidValue(), fadeMs: scaleAnimationDuration(SCREEN_FADE_MS, screenFadeSetting.get()) };
}
export const screenTimeoutSetting = new ConfigSettingEnum<ScreenTimeoutSetting>({
+4 -4
View File
@@ -326,17 +326,17 @@ function batteryIndicatorsMenuItem(): MenuItem {
};
}
/** The Customization section's "Animations" row: opens a modal submenu of animation toggles. */
/** The Customization section's "Animations" row: opens a modal submenu of animation speeds. */
function animationsMenuItem(): MenuItem {
return submenuItem(
"Animations",
(ctx) => {
openSettingsSubMenu(ctx, "Animations", [
toggleSettingMenuItem(menuAnimationSetting),
toggleSettingMenuItem(screenFadeSetting),
enumSettingMenuItem(menuAnimationSetting),
enumSettingMenuItem(screenFadeSetting),
]);
},
{ description: "Turn off menu and icon-grid motion, or the fade when the screen turns on and off." },
{ description: "Speed up, slow down, or turn off menu and icon-grid motion and the fade when the screen turns on and off." },
);
}
+11 -8
View File
@@ -1,18 +1,21 @@
import { scaleAnimationDuration, type AnimationSpeed } from "./animation-speed";
/**
* Whether menus and icon grids animate on the glasses (Settings > Customization >
* How fast menus and icon grids animate on the glasses (Settings > Customization >
* Animations > Menu animation). The motion classes can't read the settings
* store themselves (it is native, and they load under Node in unit tests),
* so ui/menu.ts installs a reader in each isolate that paints menus. Without
* one, menus animate.
* one, menus animate at Normal speed.
*/
export const MENU_ANIMATION_KEY = "display.menuAnimation";
export const MENU_ANIMATION_KEY = "display.menuAnimationSpeed";
let readMenuAnimation: () => boolean = () => true;
let readMenuAnimationSpeed: () => AnimationSpeed = () => "normal";
export function menuAnimationEnabled(): boolean {
return readMenuAnimation();
/** A menu animation's Normal-speed duration at the configured speed; 0 when menu animation is disabled. */
export function menuAnimationDurationMs(normalMs: number): number {
return scaleAnimationDuration(normalMs, readMenuAnimationSpeed());
}
export function setMenuAnimationReader(read: () => boolean): void {
readMenuAnimation = read;
export function setMenuAnimationReader(read: () => AnimationSpeed): void {
readMenuAnimationSpeed = read;
}
+5 -3
View File
@@ -1,5 +1,6 @@
import { menuAnimationEnabled } from "./menu-animation-pref";
import { menuAnimationDurationMs } from "./menu-animation-pref";
/** At Normal menu animation speed; menuAnimationDurationMs scales it to the setting. */
export const MENU_HIGHLIGHT_DURATION_MS = 240;
export type MenuHighlightAnimation = { dx: number; dy: number; startedAt: number; token: number; durationMs: number };
@@ -32,9 +33,10 @@ export class MenuHighlightMotion {
fromX += this.animation.dx * remaining;
fromY += this.animation.dy * remaining;
}
const eligible = menuAnimationEnabled() && previous && previous.index !== index && this.fromIndex === previous.index &&
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: MENU_HIGHLIGHT_DURATION_MS } : undefined;
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 };
}
+8 -6
View File
@@ -1,9 +1,10 @@
import { DrawExpression as E, ExprOp } from "../graphics/draw-expression";
import { menuAnimationEnabled } from "./menu-animation-pref";
import { menuAnimationDurationMs } from "./menu-animation-pref";
import { MENU_HIGHLIGHT_DURATION_MS, nextAnimationToken } from "./menu-highlight-motion";
/** Longest scroll, in pixels, that animates; longer jumps snap. */
export const MAX_ANIMATED_SCROLL = 96;
/** At Normal menu animation speed, like MENU_HIGHLIGHT_DURATION_MS. */
export const MENU_BOUNCE_DURATION_MS = 320;
/** Fraction of a bounce spent moving out to the peak; the rest settles back. */
const BOUNCE_PEAK = 0.35;
@@ -73,20 +74,21 @@ export class MenuScrollMotion {
/** Record this paint's settled offset; returns the animation in flight, if any. */
paint(scroll: number, box: Box, now: number): MenuScrollAnimation | undefined {
const previous = this.previous;
const enabled = menuAnimationEnabled();
const scrollMs = menuAnimationDurationMs(MENU_HIGHLIGHT_DURATION_MS);
const sameBox = !!previous && previous.box.x === box.x && previous.box.y === box.y &&
previous.box.width === box.width && previous.box.height === box.height;
if (!previous || !sameBox || previous.scroll !== scroll) {
const from = previous ? this.offsetAt(previous.scroll, now) : scroll;
const eligible = enabled && sameBox && this.navigated && from !== scroll && Math.abs(scroll - from) <= MAX_ANIMATED_SCROLL;
const eligible = scrollMs > 0 && sameBox && this.navigated && from !== scroll && Math.abs(scroll - from) <= MAX_ANIMATED_SCROLL;
this.animation = eligible
? { from, to: scroll, startedAt: now, token: nextAnimationToken(), durationMs: MENU_HIGHLIGHT_DURATION_MS }
? { from, to: scroll, startedAt: now, token: nextAnimationToken(), durationMs: scrollMs }
: undefined;
this.previous = { scroll, box: { ...box } };
} else if (this.bounceBy && enabled) {
} else if (this.bounceBy && scrollMs > 0) {
const from = this.offsetAt(scroll, now);
this.animation = Math.abs(scroll - from) <= MAX_ANIMATED_SCROLL
? { from, peak: scroll + this.bounceBy, to: scroll, startedAt: now, token: nextAnimationToken(), durationMs: MENU_BOUNCE_DURATION_MS }
? { from, peak: scroll + this.bounceBy, to: scroll, startedAt: now, token: nextAnimationToken(),
durationMs: menuAnimationDurationMs(MENU_BOUNCE_DURATION_MS) }
: undefined;
}
this.navigated = false;
+3 -2
View File
@@ -1,8 +1,9 @@
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage, type UiFont } from "../graphics/image";
import { wrapText } from "../graphics/textwrap";
import { getDefaultSmallFont } from "../graphics/ui-fonts";
import { getBooleanSetting } from "../native/settings-store";
import { getStringSetting } from "../native/settings-store";
import { clamp } from "../util/numeric-util";
import { normalizeAnimationSpeed } from "./animation-speed";
import { Layer, LayerContext, PaintBelow } from "./layers";
import { MENU_ANIMATION_KEY, setMenuAnimationReader } from "./menu-animation-pref";
import { Menu, MENU_HIGHLIGHT_FILL, MENU_HIGHLIGHT_STROKE } from "./menu-core";
@@ -12,7 +13,7 @@ import { LIST_ROW_TEXT_INSET, centeredTextY, lineStep, listRowHeight, menuTitleH
// Menu<T> and IconGrid consult this (through their motion classes) at each
// paint; a SharedPreferences read, so changes apply to the next navigation.
setMenuAnimationReader(() => getBooleanSetting(MENU_ANIMATION_KEY, true));
setMenuAnimationReader(() => normalizeAnimationSpeed(getStringSetting(MENU_ANIMATION_KEY, "normal")));
const DEFAULT_MENU_X = 8;
const DEFAULT_MENU_Y = 8;