Add animation preferences menu

This commit is contained in:
James Babcock committed 2026-09-26 20:42:08 -07:00
1 parent e6ec542f56
commit f473855710
14 files changed
+106 -5

No files matched your search

+18 -1
View File
@@ -18,6 +18,7 @@ import {
} from "~/assistant/models";
import { isLocalModelReady } from "../native/llama";
import { drawRightValueMenuItem, drawToggleMenuItem, MenuItem, openModalMenu } from "./menu";
import { MENU_ANIMATION_KEY } from "./menu-animation-pref";
import { LIST_ROW_TEXT_INSET, lineStep } from "./metrics";
import { Layer, type LayerContext } from "./layers";
import { GrayImage } from "~/graphics/image";
@@ -361,11 +362,27 @@ export const autoBrightnessCurveSetting = new ConfigSettingString({
});
const SCREEN_FADE_MS = 280;
export const menuAnimationSetting = new ConfigSettingBoolean({
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.",
});
export const screenFadeSetting = new ConfigSettingBoolean({
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.",
});
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: SCREEN_FADE_MS };
curve: autoBrightnessCurveSetting.getValidValue(), fadeMs: screenFadeSetting.get() ? SCREEN_FADE_MS : 0 };
}
export const screenTimeoutSetting = new ConfigSettingEnum<ScreenTimeoutSetting>({
+18
View File
@@ -60,9 +60,11 @@ import {
phoneRotationSetting,
ringConnectionModeSetting,
sonioxApiKeySetting,
screenFadeSetting,
enumSettingMenuItem,
firmwareDebugFlagsSetting,
lockScreenEnabledSetting,
menuAnimationSetting,
saveVoiceRecordingsSetting,
showBleBandwidthSetting,
suspendEvenHubWhenScreenOffSetting,
@@ -114,6 +116,8 @@ function settingsSections(): SettingsSection[] {
enumSettingMenuItem(displayModeSetting),
// Submenu: top-bar battery indicator style plus per-device visibility.
batteryIndicatorsMenuItem(),
// Submenu: toggles for menu/icon-grid motion and the screen on/off fade.
animationsMenuItem(),
// Controls the top-bar clock (24-hour vs 12-hour).
enumSettingMenuItem(timeFormatSetting),
// Opens the modal font picker (face, weight, size) for UI text.
@@ -312,6 +316,20 @@ function batteryIndicatorsMenuItem(): MenuItem {
};
}
/** The Display section's "Animations" row: opens a modal submenu of animation toggles. */
function animationsMenuItem(): MenuItem {
return {
label: "Animations",
description: "Turn off menu and icon-grid motion, or the fade when the screen turns on and off.",
onSelect: (ctx) => {
openSettingsSubMenu(ctx, "Animations", [
toggleSettingMenuItem(menuAnimationSetting),
toggleSettingMenuItem(screenFadeSetting),
]);
},
};
}
const LOCAL_MODEL_GB = `${(LOCAL_MODEL.sizeBytes / 1e9).toFixed(1)}GB`;
// While a download is running, re-render on progress updates so the row's
+18
View File
@@ -0,0 +1,18 @@
/**
* Whether menus and icon grids animate on the glasses (Settings > Display >
* 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.
*/
export const MENU_ANIMATION_KEY = "display.menuAnimation";
let readMenuAnimation: () => boolean = () => true;
export function menuAnimationEnabled(): boolean {
return readMenuAnimation();
}
export function setMenuAnimationReader(read: () => boolean): void {
readMenuAnimation = read;
}
+3 -1
View File
@@ -1,3 +1,5 @@
import { menuAnimationEnabled } from "./menu-animation-pref";
export const MENU_HIGHLIGHT_DURATION_MS = 240;
export type MenuHighlightAnimation = { dx: number; dy: number; startedAt: number; token: number; durationMs: number };
@@ -30,7 +32,7 @@ export class MenuHighlightMotion {
fromX += this.animation.dx * remaining;
fromY += this.animation.dy * remaining;
}
const eligible = previous && previous.index !== index && this.fromIndex === previous.index &&
const eligible = menuAnimationEnabled() && 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.fromIndex = null;
+4 -2
View File
@@ -1,4 +1,5 @@
import { DrawExpression as E, ExprOp } from "../graphics/draw-expression";
import { menuAnimationEnabled } from "./menu-animation-pref";
import { MENU_HIGHLIGHT_DURATION_MS, nextAnimationToken } from "./menu-highlight-motion";
/** Longest scroll, in pixels, that animates; longer jumps snap. */
@@ -72,16 +73,17 @@ 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 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 = sameBox && this.navigated && from !== scroll && Math.abs(scroll - from) <= MAX_ANIMATED_SCROLL;
const eligible = enabled && 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 }
: undefined;
this.previous = { scroll, box: { ...box } };
} else if (this.bounceBy) {
} else if (this.bounceBy && enabled) {
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 }
+7
View File
@@ -1,12 +1,19 @@
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 { clamp } from "../util/numeric-util";
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";
import { GESTURE_DOUBLE_CLICK, InputEvent } from "./gestures";
import { LIST_ROW_TEXT_INSET, centeredTextY, lineStep, listRowHeight, menuTitleHeight } from "./metrics";
// 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));
const DEFAULT_MENU_X = 8;
const DEFAULT_MENU_Y = 8;
const DEFAULT_MENU_WIDTH = 272;
+7
View File
@@ -22,6 +22,7 @@ function settingsFixture(store = new Map()) {
if (id.includes('settings-store')) return {
onSettingsStoreChanged() {}, getStringSetting: (k, d) => store.get(k) ?? d,
setStringSetting: (k, v) => store.set(k, v),
getBooleanSetting: (k, d) => store.get(k) ?? d, setBooleanSetting: (k, v) => store.set(k, v),
};
if (id.includes('brightness-curve')) return require('../.test-build/app/g2/brightness-curve.js');
return { Layer: class {}, ASSISTANT_MODEL_CHOICES: [] };
@@ -35,6 +36,12 @@ test('auto minimum defaults to 20 and preserves a saved preference', () => {
assert.equal(settingsFixture().getBrightnessPreferences().minimum, 20);
assert.equal(settingsFixture(new Map([['display.autoBrightnessMin', '25']])).getBrightnessPreferences().minimum, 25);
});
test('the screen fade setting switches the on/off fade between 280 ms and instant', () => {
const api = settingsFixture();
assert.equal(api.getBrightnessPreferences().fadeMs, 280);
api.screenFadeSetting.set(false);
assert.equal(api.getBrightnessPreferences().fadeMs, 0);
});
test('curve drafts preview exactly while brightness keeps the previous valid saved curve', () => {
const store = new Map([['display.autoBrightnessCurve', '0:0,2:50,8:100']]);
let api = settingsFixture(store), curve = api.autoBrightnessCurveSetting;
+1
View File
@@ -27,6 +27,7 @@ const layers = load('app/ui/layers.ts', {
'../native/frame-timings': { spanCurrent: (_name, paint) => paint() },
});
const menu = load('app/ui/menu.ts', {
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), '../native/settings-store': { getBooleanSetting: (_key, fallback) => fallback },
'./menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'),
'../graphics/image': graphics, '../graphics/ui-fonts': fonts, '../graphics/textwrap': textwrap,
'../util/numeric-util': numeric, './gestures': gestures, './metrics': load('app/ui/metrics.ts'),
+5 -1
View File
@@ -60,7 +60,11 @@ function loadIconGrid({ lastInputWasWatch = false } = {}) {
'./menu-core': build('ui/menu-core'),
'./metrics': metrics,
};
const menu = load('app/ui/menu.ts', { ...common, './layers': {} });
const menu = load('app/ui/menu.ts', {
...common, './layers': {},
'./menu-animation-pref': build('ui/menu-animation-pref'),
'../native/settings-store': { getBooleanSetting: (_key, fallback) => fallback },
});
const grid = load('app/ui/icon-grid.ts', {
...common,
'../graphics/draw-expression': build('graphics/draw-expression'),
+1
View File
@@ -19,6 +19,7 @@ const menuCore=load('app/ui/menu-core.ts',{
'../graphics/image':graphics,'./menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'),
});
const {MenuLayer}=load('app/ui/menu.ts',{
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), '../native/settings-store': { getBooleanSetting: (_key, fallback) => fallback },
'../graphics/image':graphics,'../graphics/textwrap':{},'../graphics/ui-fonts':{getDefaultSmallFont:()=>font},
'../util/numeric-util':{clamp:(n,a,b)=>Math.max(a,Math.min(b,n))},'./gestures':{},
'./menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'),
+21
View File
@@ -9,6 +9,7 @@ const { DrawExpression: E } = require('../.test-build/app/graphics/draw-expressi
const { menuScrollList, slidingHighlightY } = require('../.test-build/app/graphics/menu-scroll-list.js');
const { MENU_BOUNCE_DURATION_MS, scrollOffsetExpression } = require('../.test-build/app/ui/menu-scroll-motion.js');
const { encodePresentation } = require('../.test-build/app/graphics/presentation-wire.js');
const { setMenuAnimationReader } = require('../.test-build/app/ui/menu-animation-pref.js');
// Also consumed by FrameDisplayListTest.kt.
const SCROLL = '078a000000030002000400020000070000009600000001000200040011223344556677880200020000000000ff250100300102300180f0800180f0161101001732800180f01610300180f0302341403101001102000200010008000000ff280101300100300180f0800180f0161101001732800180f01610300180f030234140310100170100160400020000000103';
@@ -196,6 +197,26 @@ test('a bounce during a scroll starts from the offset on screen', () => {
assert.ok(offsets[0] < offsets[1], 'it starts where the scroll had got to, above its settled offset');
});
test('with menu animation off, scrolls, slides and bounces snap', (t) => {
setMenuAnimationReader(() => false);
t.after(() => setMenuAnimationReader(() => true));
const timed = (image) => image.draws.filter((draw) => draw.presentation?.displayList?.timeline);
const menu = inkMenu();
paint(menu, 1000);
menu.moveSelection(1);
const slid = paint(menu, 2000);
assert.equal(menu.scrollTop, 0);
assert.equal(timed(slid).length, 0, 'the highlight snaps');
menu.moveSelection(1);
const scrolled = paint(menu, 3000);
assert.equal(menu.scrollTop, 20);
assert.equal(timed(scrolled).length, 0, 'the scroll snaps');
menu.select(6);
paint(menu, 4000);
menu.moveSelection(1);
assert.equal(timed(paint(menu, 5000)).length, 0, 'no bounce');
});
test('scroll lists survive the bridge with animated copy coordinates', () => {
const strip = { width: 2, height: 4, pixels: Uint8Array.of(17, 34, 51, 68, 85, 102, 119, 136) };
const timeline = { from: 0, to: 2, startedAt: 1000, token: 7, durationMs: MENU_HIGHLIGHT_DURATION_MS };
+1
View File
@@ -155,6 +155,7 @@ test('Music settings keeps toggles and selection when a new app arrives and supp
'../util/numeric-util': { clamp: (n, lo, hi) => Math.max(lo, Math.min(hi, n)) },
'./menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'),
'./metrics': load('app/ui/metrics.ts'), './gestures': {},
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), '../native/settings-store': { getBooleanSetting: (_key, fallback) => fallback },
};
deps['./menu-core'] = load('app/ui/menu-core.ts', (name) => deps[name]);
const menu = load('app/ui/menu.ts', (name) => deps[name]);
+1
View File
@@ -86,6 +86,7 @@ function ui(fontSize = 12) {
'../util/render-freshness': { renderPassAllowsStaleData: () => false },
'./menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'),
'./metrics': load('app/ui/metrics.ts'),
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), '../native/settings-store': { getBooleanSetting: (_key, fallback) => fallback },
'./gestures': {},
};
const requireModule = (name) => {
+1
View File
@@ -22,6 +22,7 @@ const font = BdfFont.parse(fs.readFileSync(path.join(__dirname, '../app/fonts/te
const textwrap = load('app/graphics/textwrap.ts', {});
const fonts = { getDefaultSmallFont: () => font };
const menu = load('app/ui/menu.ts', {
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), '../native/settings-store': { getBooleanSetting: (_key, fallback) => fallback },
'../graphics/image': graphics, '../graphics/textwrap': textwrap, '../graphics/ui-fonts': fonts,
'../util/numeric-util': { clamp: (n, lo, hi) => Math.max(lo, Math.min(hi, n)) }, './gestures': {},
'./metrics': metrics, './menu-core': menuCore,