forked from Blendman974/faceclaw
Add animation preferences menu
This commit is contained in:
1 parent
e6ec542f56
commit
f473855710
14 files changed
+106
-5
No files matched your search
@@ -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>({
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user