diff --git a/app/ui/dashboard-settings.ts b/app/ui/dashboard-settings.ts index 6eec38d3..01ffac01 100644 --- a/app/ui/dashboard-settings.ts +++ b/app/ui/dashboard-settings.ts @@ -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({ diff --git a/app/ui/dashboard/settings-menus.ts b/app/ui/dashboard/settings-menus.ts index a51af850..6a24ee4c 100644 --- a/app/ui/dashboard/settings-menus.ts +++ b/app/ui/dashboard/settings-menus.ts @@ -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 diff --git a/app/ui/menu-animation-pref.ts b/app/ui/menu-animation-pref.ts new file mode 100644 index 00000000..40381fb2 --- /dev/null +++ b/app/ui/menu-animation-pref.ts @@ -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; +} diff --git a/app/ui/menu-highlight-motion.ts b/app/ui/menu-highlight-motion.ts index b10e16fd..71a2dd53 100644 --- a/app/ui/menu-highlight-motion.ts +++ b/app/ui/menu-highlight-motion.ts @@ -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; diff --git a/app/ui/menu-scroll-motion.ts b/app/ui/menu-scroll-motion.ts index 85540825..ec098007 100644 --- a/app/ui/menu-scroll-motion.ts +++ b/app/ui/menu-scroll-motion.ts @@ -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 } diff --git a/app/ui/menu.ts b/app/ui/menu.ts index 39af0a14..dc64c901 100644 --- a/app/ui/menu.ts +++ b/app/ui/menu.ts @@ -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 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; diff --git a/tests/brightness-curve.test.cjs b/tests/brightness-curve.test.cjs index 03db54e2..1f81e744 100644 --- a/tests/brightness-curve.test.cjs +++ b/tests/brightness-curve.test.cjs @@ -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; diff --git a/tests/brightness-picker.test.cjs b/tests/brightness-picker.test.cjs index 4c793b4d..a8a07672 100644 --- a/tests/brightness-picker.test.cjs +++ b/tests/brightness-picker.test.cjs @@ -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'), diff --git a/tests/icon-grid.test.cjs b/tests/icon-grid.test.cjs index d8f48594..79e78324 100644 --- a/tests/icon-grid.test.cjs +++ b/tests/icon-grid.test.cjs @@ -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'), diff --git a/tests/menu-display-list.test.cjs b/tests/menu-display-list.test.cjs index fdfe12df..57a57a6b 100644 --- a/tests/menu-display-list.test.cjs +++ b/tests/menu-display-list.test.cjs @@ -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'), diff --git a/tests/menu-scroll-animation.test.cjs b/tests/menu-scroll-animation.test.cjs index cf7047c8..112a2a9c 100644 --- a/tests/menu-scroll-animation.test.cjs +++ b/tests/menu-scroll-animation.test.cjs @@ -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 }; diff --git a/tests/music-settings.test.cjs b/tests/music-settings.test.cjs index 97da8432..d40b3f9d 100644 --- a/tests/music-settings.test.cjs +++ b/tests/music-settings.test.cjs @@ -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]); diff --git a/tests/notification-filter.test.cjs b/tests/notification-filter.test.cjs index 90e57a9c..ea1be2bd 100644 --- a/tests/notification-filter.test.cjs +++ b/tests/notification-filter.test.cjs @@ -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) => { diff --git a/tests/settings-panel.test.cjs b/tests/settings-panel.test.cjs index dcfbabac..0a6b2448 100644 --- a/tests/settings-panel.test.cjs +++ b/tests/settings-panel.test.cjs @@ -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,