Merge branch 'main' of https://github.com/jimrandomh/faceclaw into ring-health-fixes

This commit is contained in:
James Babcock committed 2026-09-26 23:01:41 -07:00
commit a8c9ab0a98
27 files changed
+528 -77

No files matched your search

+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'),
+14
View File
@@ -89,3 +89,17 @@ test("an omitted or out-of-range textColor falls back to the device default", ()
assert.equal(page.containers[0].textColor, undefined);
}
});
test("borderWidth is clamped to stock's maximum of 5", () => {
const page = parsePage({
listObject: [{ containerID: 1, containerName: "l", borderWidth: 9 }],
textObject: [{ containerID: 2, containerName: "t", borderWidth: 12 }, { containerID: 3, containerName: "u", borderWidth: 3 }],
});
assert.deepEqual(page.containers.map((c) => c.borderWidth), [5, 5, 3]);
});
test("a list without isItemSelectBorderEn has no selection border (protobuf default 0)", () => {
const page = parsePage({ listObject: [{ containerID: 1, containerName: "l", itemContainer: { itemName: ["a"] } }] });
assert.equal(page.containers[0].selectBorder, false);
assert.equal(page.containers[0].itemWidth, 0);
});
+148
View File
@@ -0,0 +1,148 @@
// EvenHub list containers in the stock style, on the shared Menu: dim
// unselected text, a text-sized outline, animated scrolling and bounce, and a
// selection that moves instantly.
const test = require("node:test");
const assert = require("node:assert/strict");
const {
paintListItems, stepListSelection, listRowHeight, truncateToWidth, DESELECTED_TEXT, LIST_ITEM_PADDING_X, LIST_ITEM_PADDING_Y,
} = require("../.test-build/app/apps/evenhub/list-menu.js");
const { GrayImage } = require("../.test-build/app/graphics/image.js");
const { DrawOp } = require("../.test-build/app/graphics/display-list.js");
/** Each character is a 6x10 block of ink at 10px advance. */
const font = {
lineHeight: 20,
measureLine: (text) => text.length * 10,
drawText: (image, x, y, text, value = 255) => {
for (let i = 0; i < text.length; i++) image.fillRect(x + i * 10, y + 4, 6, 10, value);
},
};
function list(itemNames, height) {
return {
kind: "list", id: 1, name: "list", x: 0, y: 0, width: 200, height,
borderWidth: 0, borderRadius: 0, paddingLength: 0, isEventCapture: true, zOrderIndex: undefined,
preserve: false, itemNames, itemWidth: 0, selectBorder: true, selectedIndex: 0,
};
}
function paint(container, now, focused = true) {
const original = Date.now;
Date.now = () => now;
try {
const image = new GrayImage(200, 200, 0);
paintListItems(image, container, font, focused);
return image;
} finally {
Date.now = original;
}
}
const displayLists = (image) => image.draws.map((draw) => draw.presentation?.displayList).filter(Boolean);
const pixel = (image, x, y) => image.withDrawsBaked().pixels[y * image.width + x];
test("rows are padded 6px around the text; unselected text is at level 2/15", () => {
const rowHeight = listRowHeight(font);
assert.equal(rowHeight, 32);
const container = list(["ab", "cd"], 100);
const image = paint(container, 1000);
const textX = LIST_ITEM_PADDING_X, textY = LIST_ITEM_PADDING_Y + 4;
assert.equal(pixel(image, textX, textY), 255, "selected text is full brightness");
assert.equal(pixel(image, textX, rowHeight + textY), DESELECTED_TEXT, "unselected text is 2/15");
assert.equal(DESELECTED_TEXT + 8 >> 4, 2);
// The outline hugs the text plus padding, not the row width.
const outlineRight = 2 * 10 + 2 * LIST_ITEM_PADDING_X - 1;
assert.equal(pixel(image, outlineRight, rowHeight / 2), 255);
assert.equal(pixel(image, outlineRight + 2, rowHeight / 2), 0);
});
test("the unfocused outline is dimmer", () => {
const image = paint(list(["ab"], 100), 1000, false);
assert.equal(pixel(image, 0, 16), 130);
});
test("selection within the viewport changes instantly, with no animation", () => {
const container = list(["a", "b", "c", "d", "e", "f"], 128);
paint(container, 1000);
assert.equal(stepListSelection(container, font, 1), true);
assert.equal(container.selectedIndex, 1);
const image = paint(container, 2000);
assert.deepEqual(displayLists(image), []);
});
test("navigation that scrolls animates a strip", () => {
const container = list(["a", "b", "c", "d", "e", "f"], 128);
paint(container, 1000);
for (let i = 0; i < 3; i++) {
stepListSelection(container, font, 1);
paint(container, 1000 + i);
}
assert.equal(container.selectedIndex, 3);
const scrolled = displayLists(paint(container, 5000));
assert.deepEqual(scrolled, [], "settled paints don't animate");
stepListSelection(container, font, 1);
const [strip] = displayLists(paint(container, 6000));
assert.ok(strip?.calls.some((call) => call.op === DrawOp.RECT_COPY), "the scroll animates");
assert.ok(!strip.calls.some((call) => call.op === DrawOp.ROUNDED_RECT), "no separate sliding highlight");
});
test("stepping past an end keeps the selection and bounces", () => {
const container = list(["a", "b", "c", "d", "e", "f"], 128);
paint(container, 1000);
assert.equal(stepListSelection(container, font, -1), false);
assert.equal(container.selectedIndex, 0);
const [bounce] = displayLists(paint(container, 2000));
assert.ok(bounce?.calls.some((call) => call.op === DrawOp.RECT_COPY), "the list bounces");
});
test("a row cut by the bottom edge is drawn clipped", () => {
// 100px fits three 32px rows and the top 4px of the fourth, whose ink
// starts 10px into the row, so a 16px taller box shows its first 10 lines.
const clipped = paint(list(["a", "b", "c", "d"], 100), 1000);
const textTop = 3 * 32 + LIST_ITEM_PADDING_Y + 4;
assert.equal(pixel(clipped, LIST_ITEM_PADDING_X, textTop), 0, "below the edge");
const partial = paint(list(["a", "b", "c", "d"], 3 * 32 + 16), 1000);
assert.equal(pixel(partial, LIST_ITEM_PADDING_X, 3 * 32 + 16), 0, "nothing past the edge");
assert.equal(pixel(partial, LIST_ITEM_PADDING_X, textTop), DESELECTED_TEXT, "the visible part is drawn");
});
test("at the end of a list with a partial row, the top row stays whole", () => {
const container = list(["a", "b", "c", "d", "e"], 3 * 32 + 16);
paint(container, 1000);
for (let i = 0; i < 4; i++) {
stepListSelection(container, font, 1);
paint(container, 1000 + i);
}
const image = paint(container, 9000);
// As in every Menu, the viewport never starts on a partial row: c, d and
// e show whole, leaving 16px empty below e rather than cutting c in half.
assert.equal(pixel(image, LIST_ITEM_PADDING_X, LIST_ITEM_PADDING_Y + 4), DESELECTED_TEXT, "c at the top");
assert.equal(pixel(image, LIST_ITEM_PADDING_X, 64 + LIST_ITEM_PADDING_Y + 4), 255, "e selected, third row");
});
test("with the selection border off, the selected item has no outline", () => {
const container = { ...list(["ab"], 100), selectBorder: false };
const image = paint(container, 1000);
assert.equal(pixel(image, 0, 16), 0, "no outline edge");
assert.equal(pixel(image, LIST_ITEM_PADDING_X, LIST_ITEM_PADDING_Y + 4), 255, "text still selected-bright");
});
test("a fixed itemWidth sets the outline's width exactly", () => {
const container = { ...list(["ab"], 100), itemWidth: 150 };
const image = paint(container, 1000);
assert.equal(pixel(image, 149, 16), 255, "right edge at itemWidth");
assert.equal(pixel(image, 150, 16), 0);
});
test("text wider than a fixed itemWidth is truncated with an ellipsis", () => {
// 10px per char: 100 - 2 * 12 = 76px holds "abcd..." (70px) but not "abcde..." (80px).
assert.equal(truncateToWidth(font, "abcdefghij", 76), "abcd...");
assert.equal(truncateToWidth(font, "abcdefg", 76), "abcdefg", "fits: unchanged");
assert.equal(truncateToWidth(font, "abcdefgh", 20), "...", "room for nothing but the ellipsis");
const drawn = [];
const recording = { ...font, drawText: (image, x, y, text, value) => { drawn.push(text); font.drawText(image, x, y, text, value); } };
const image = new GrayImage(200, 200, 0);
paintListItems(image, { ...list(["abcdefghij", "ab"], 100), itemWidth: 100 }, recording, true);
assert.deepEqual(drawn, ["abcd...", "ab"]);
});
+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,
+1
View File
@@ -45,6 +45,7 @@
"../app/apps/microphones/radar-dots.ts",
"../app/apps/microphones/name-guess.ts",
"../app/apps/evenhub/containers.ts",
"../app/apps/evenhub/list-menu.ts",
"../app/apps/timer/timer-model.ts",
"../app/apps/teleprompter/script-tracker.ts",
"../app/apps/nightscout/nightscout-alerts.ts",