forked from Blendman974/faceclaw
feat: isolate notification popups and scroll selected menu labels
This commit is contained in:
1 parent
b4a2b2931b
commit
22df4d76d9
14 files changed
+577
-26
No files matched your search
@@ -33,7 +33,7 @@ const menu = load('app/ui/menu.ts', {
|
||||
'../graphics/image': graphics, '../graphics/ui-fonts': fonts, '../graphics/textwrap': textwrap,
|
||||
'../util/numeric-util': numeric, './gestures': gestures, './metrics': load('app/ui/metrics.ts'),
|
||||
'./menu-core': 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'),
|
||||
'../graphics/image': graphics, './menu-label': require('../.test-build/app/ui/menu-label.js'), './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'),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ const bdf = (size) => BdfFont.parse(fs.readFileSync(path.join(__dirname, `../app
|
||||
const font = bdf(14);
|
||||
const textwrap = load('app/graphics/textwrap.ts', {});
|
||||
const coreDeps = {
|
||||
'./menu-label': build('ui/menu-label'),
|
||||
'../graphics/image': graphics, './menu-highlight-motion': build('ui/menu-highlight-motion'),
|
||||
'../graphics/menu-scroll-list': build('graphics/menu-scroll-list'), './menu-scroll-motion': build('ui/menu-scroll-motion'),
|
||||
'../graphics/draw-expression': build('graphics/draw-expression'),
|
||||
|
||||
@@ -15,7 +15,7 @@ function load(file,modules) {
|
||||
const font={lineHeight:12,ascent:10,descent:2,measureText:text=>text.length*4,
|
||||
drawText:(image,x,y,text,value)=>{for(let i=0;i<text.length;i++) image.fillRect(x+i*4,y+2,2,6,value);}};
|
||||
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'),
|
||||
'../graphics/image':graphics,'./menu-label': require('../.test-build/app/ui/menu-label.js'), './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,TextPageLayer}=load('app/ui/menu.ts',{
|
||||
'./menu-animation-pref': require('../.test-build/app/ui/menu-animation-pref.js'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback }, '../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
|
||||
@@ -121,13 +121,13 @@ test('unselected sidebar icons retain -2 depth through shell cropping, including
|
||||
});
|
||||
test('shell modal carries its inner menu highlight animation instead of baking its first frame',async()=>{
|
||||
const {ShellModalLayer}=load('app/ui/shell/modal-layer.ts',{
|
||||
'../../graphics/image':graphics,'../../graphics/plane':planes,'../gestures':{},'../layers':load('app/ui/layers.ts',{
|
||||
'../../graphics/image':graphics,'../../graphics/display-list':require('../.test-build/app/graphics/display-list.js'),'../../graphics/plane':planes,'../gestures':{},'../layers':load('app/ui/layers.ts',{
|
||||
'../graphics/image':graphics,'../graphics/plane':planes,'../native/frame-timings':{spanCurrent:(_name,fn)=>fn()},'../graphics/screen-size':{screenWidth:()=>640,screenHeight:()=>480},
|
||||
'./gestures':{isDirectionalInput:()=>false},
|
||||
}),
|
||||
'./geometry':{appViewportSize:()=>({width:120,height:110}),appViewportRect:()=>({x:10,y:20,width:120,height:110}),SHELL_OPAQUE_BLACK:1},
|
||||
});
|
||||
const modal=new ShellModalLayer(menu().layer,noopLayerActions),paint=()=>modal.paint({},()=>new graphics.GrayImage(200,200));
|
||||
const modal=new ShellModalLayer(menu().layer,noopLayerActions),paint=()=>modal.paint({stack:{getBaseSize:()=>({width:200,height:200})}},()=>new graphics.GrayImage(200,200));
|
||||
const bare=menu().paint().draws.find(d=>d.presentation),before=paint().draws.find(d=>d.presentation);
|
||||
assert.equal(before.x,bare.x+28);assert.equal(before.y,bare.y+38); // translated into the box interior
|
||||
await modal.handleInput({type:'scroll-down'},{});
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { GrayImage } = require('../.test-build/app/graphics/image.js');
|
||||
const { Menu } = require('../.test-build/app/ui/menu-core.js');
|
||||
const { paintDisplayList } = require('../.test-build/app/graphics/display-list.js');
|
||||
const pref = require('../.test-build/app/ui/menu-animation-pref.js');
|
||||
// Distinctive ink at the tail proves the full label, not an ellipsis, is rasterized.
|
||||
const font = { lineHeight: 8, measureText: s => s.length * 4,
|
||||
drawText(image, x, y, text, value) {
|
||||
for (let i = 0; i < text.length; i++) image.fillRect(x + i * 4, y, text[i] === 'Z' ? 3 : 1, 4, value);
|
||||
} };
|
||||
function fixture() {
|
||||
const labels = ['abcdefghijkZ', 'short'];
|
||||
const menu = new Menu({ items: labels, getHeight: () => 12,
|
||||
draw: ({ image, item, x, y, width, drawLabel }) => {
|
||||
if (drawLabel) drawLabel(font, x + 3, y + 2, width - 6, item, 240);
|
||||
else image.drawText(font, x + 3, y + 2, item, 240);
|
||||
} });
|
||||
return { menu, labels, paint(focused = true, width = 30) {
|
||||
const image = new GrayImage(50, 30); menu.paint(image, { x: 2, y: 1, width, height: 24 }, focused); return image;
|
||||
} };
|
||||
}
|
||||
const fs = require('node:fs');
|
||||
const vm = require('node:vm');
|
||||
const ts = require('typescript');
|
||||
function load(file, modules) {
|
||||
const context = { exports: {}, require: name => { assert.ok(name in modules, name); return modules[name]; } };
|
||||
vm.runInNewContext(ts.transpileModule(fs.readFileSync(file, 'utf8'), {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
||||
}).outputText, context);
|
||||
return context.exports;
|
||||
}
|
||||
const menuModule = load('app/ui/menu.ts', {
|
||||
'../graphics/image': { GrayImage }, '../graphics/screen-size': { screenHeight: () => 480 },
|
||||
'../graphics/textwrap': {}, '../graphics/ui-fonts': { getDefaultSmallFont: () => font },
|
||||
'../native/settings-store': { getStringSetting: (_key, fallback) => fallback },
|
||||
'../util/numeric-util': { clamp: (n, lo, hi) => Math.max(lo, Math.min(hi, n)) },
|
||||
'./animation-speed': require('../.test-build/app/ui/animation-speed.js'), './layers': {}, './gestures': {},
|
||||
'./menu-animation-pref': pref, './menu-core': require('../.test-build/app/ui/menu-core.js'),
|
||||
'./metrics': require('../.test-build/app/ui/metrics.js'),
|
||||
});
|
||||
const lists = image => image.draws.filter(d => d.presentation?.displayList?.timeline);
|
||||
test('selected overflowing label is retained, initially paused, then reveals its tail inside its clip', () => {
|
||||
const f = fixture();
|
||||
const image = f.paint();
|
||||
const moving = lists(image);
|
||||
assert.equal(moving.length, 1);
|
||||
const d = moving[0], list = d.presentation.displayList;
|
||||
const render = ms => {
|
||||
const pixels = new Uint8Array(50 * 30).fill(64);
|
||||
paintDisplayList(pixels, pixels.slice(), 50, 30,
|
||||
{ displayList: { ...list, presentedAt: list.timeline.startedAt }, x: d.x, y: d.y, width: d.source.width, height: d.source.height, depth: 0 }, false, list.timeline.startedAt + ms);
|
||||
return pixels;
|
||||
};
|
||||
assert.deepEqual(render(0), render(700));
|
||||
assert.notDeepEqual(render(0), render(1800));
|
||||
assert.equal(render(1800)[3 * 50 + 27], 240, 'tail Z reaches the right edge');
|
||||
assert.equal(render(1800)[3 * 50 + 29], 64, 'right inset is untouched');
|
||||
assert.equal(render(1800)[13 * 50 + 8], 64, 'next row is untouched');
|
||||
});
|
||||
|
||||
test('short, unselected, unfocused and disabled-animation labels stay clipped and static', () => {
|
||||
const f = fixture();
|
||||
assert.equal(lists(f.paint(false)).length, 0);
|
||||
f.menu.select(1);
|
||||
assert.equal(lists(f.paint()).length, 0);
|
||||
pref.setMenuAnimationReader(() => 'disabled');
|
||||
try {
|
||||
f.menu.select(0);
|
||||
const image = f.paint();
|
||||
assert.equal(lists(image).length, 0);
|
||||
const row = image.draws.find(d => d.presentation).source;
|
||||
assert.ok(row.pixels.some(v => v === 240), 'static label remains readable');
|
||||
for (let y = 0; y < row.height; y++) assert.equal(row.getPixel(28, y), 0, 'right inset stays clear');
|
||||
} finally { pref.setMenuAnimationReader(() => 'normal'); }
|
||||
});
|
||||
|
||||
test('same retained presentation keeps its clock across paints and resets on content, width and focus', () => {
|
||||
const original = Date.now;
|
||||
let now = 1000;
|
||||
Date.now = () => now;
|
||||
try {
|
||||
const f = fixture();
|
||||
const timeline = () => lists(f.paint())[0].presentation.displayList.timeline;
|
||||
const first = timeline();
|
||||
now = 1500;
|
||||
assert.deepEqual(timeline(), first);
|
||||
f.labels[0] += 'Z';
|
||||
const content = timeline();
|
||||
assert.equal(content.startedAt, 1500);
|
||||
assert.notEqual(content.token, first.token);
|
||||
const resized = lists(f.paint(true, 28))[0].presentation.displayList.timeline;
|
||||
assert.notEqual(resized.token, content.token);
|
||||
f.paint(false);
|
||||
assert.notEqual(timeline().token, resized.token);
|
||||
} finally { Date.now = original; }
|
||||
});
|
||||
|
||||
test('retained label pauses at the end, returns, stops scheduling, and survives a later PRESENT', () => {
|
||||
const { evaluate } = require('../.test-build/app/graphics/draw-expression.js');
|
||||
const { encodeDisplayList, readDisplayList } = require('../.test-build/app/graphics/display-list.js');
|
||||
const d = lists(fixture().paint())[0];
|
||||
const list = d.presentation.displayList;
|
||||
const offset = ms => evaluate(list.calls[0].dx, 0, ms);
|
||||
assert.equal(offset(1700).value, -24);
|
||||
assert.equal(offset(2400).value, -24);
|
||||
assert.equal(offset(3400).value, 0);
|
||||
assert.equal(offset(100000).pending, false, 'native refresh becomes idle after the bounded pass');
|
||||
const placed = { displayList: list, x: d.x, y: d.y, width: d.source.width, height: d.source.height, depth: 0 };
|
||||
const start = list.timeline.startedAt;
|
||||
const bytes = encodeDisplayList(placed, start + 1400);
|
||||
const replay = readDisplayList(bytes, 0, 10000).placed;
|
||||
assert.equal(evaluate(replay.displayList.calls[0].dx, 1400, 0).value, offset(1400).value);
|
||||
});
|
||||
|
||||
test('very long labels are tiled into firmware-valid resources rather than giant images', () => {
|
||||
const { encodeDisplayList } = require('../.test-build/app/graphics/display-list.js');
|
||||
const f = fixture(); f.labels[0] = 'a'.repeat(1000) + 'Z';
|
||||
const d = lists(f.paint())[0];
|
||||
const list = d.presentation.displayList;
|
||||
assert.ok(list.resources.length > 1);
|
||||
assert.equal(list.resources.reduce((n, r) => n + r.width, 0), 4004, 'the entire label is retained');
|
||||
for (const r of list.resources) {
|
||||
assert.ok(r.width <= 640);
|
||||
assert.ok(5 + Math.ceil(r.width / 2) * r.height <= 65536);
|
||||
}
|
||||
assert.doesNotThrow(() => encodeDisplayList({ displayList: list, x: d.x, y: d.y, width: d.source.width, height: d.source.height, depth: 0 }));
|
||||
});
|
||||
|
||||
test('selected marquee clips to a short menu viewport rather than painting below it', () => {
|
||||
const f = fixture();
|
||||
const image = new GrayImage(50, 30);
|
||||
f.menu.paint(image, { x: 2, y: 1, width: 30, height: 5 }, true);
|
||||
const d = lists(image)[0];
|
||||
assert.ok(d);
|
||||
const clip = d.presentation.displayList.calls[0].clip;
|
||||
assert.ok(d.y + clip.y + clip.height <= 6);
|
||||
});
|
||||
|
||||
test('setItems changing selection restarts the pass without restarting unchanged settings repaints', () => {
|
||||
const f = fixture();
|
||||
const first = lists(f.paint())[0].presentation.displayList.timeline.token;
|
||||
f.menu.setItems(f.labels);
|
||||
assert.equal(lists(f.paint())[0].presentation.displayList.timeline.token, first);
|
||||
f.menu.setItems(f.labels, 1);
|
||||
f.menu.setItems(f.labels, 0);
|
||||
assert.notEqual(lists(f.paint())[0].presentation.displayList.timeline.token, first);
|
||||
});
|
||||
|
||||
test('selection away and back restarts the reading pass even without an intermediate paint', () => {
|
||||
const f = fixture();
|
||||
const before = lists(f.paint())[0].presentation.displayList.timeline;
|
||||
f.menu.select(1);
|
||||
f.menu.select(0);
|
||||
const after = lists(f.paint())[0].presentation.displayList.timeline;
|
||||
assert.notEqual(after.token, before.token);
|
||||
});
|
||||
|
||||
test('common row builders scroll only the label and reserve fixed right decorations', () => {
|
||||
const label = 'abcdefghijklmnopqrstuvwxyzZ';
|
||||
const items = [
|
||||
menuModule.submenuItem(label, () => {}),
|
||||
{ label, onSelect() {}, render: a => menuModule.drawToggleMenuItem(a.image, font, a.x, a.y, a.width, a.text, true, a.selected) },
|
||||
{ label, onSelect() {}, render: a => menuModule.drawRightValueMenuItem(a.image, font, a.x, a.y, a.width, a.text, '42') },
|
||||
];
|
||||
for (const [i, item] of items.entries()) {
|
||||
const layer = new menuModule.MenuLayer(null, [item], { x: 0, y: 0, width: 140, minHeight: 40, maxHeight: 50 });
|
||||
const image = layer.paint({ stack: { getBaseSize: () => ({ width: 140, height: 60 }), isFocused: () => true } }, () => new GrayImage(140, 60));
|
||||
const scrolling = lists(image);
|
||||
assert.equal(scrolling.length, 1, `builder ${i}`);
|
||||
assert.ok(scrolling[0].source.width < 140 - 44, 'right decoration has reserved space');
|
||||
const render = ms => {
|
||||
const pixels = image.withDrawsBaked(false).pixels.slice();
|
||||
for (const d of image.draws) {
|
||||
const list = d.presentation?.displayList;
|
||||
if (!list) continue;
|
||||
const origin = list.timeline?.startedAt ?? 0;
|
||||
paintDisplayList(pixels, pixels.slice(), 140, 60,
|
||||
{ displayList: { ...list, presentedAt: origin }, x: d.x, y: d.y,
|
||||
width: d.source.width, height: d.source.height, depth: 0 }, false, origin + ms);
|
||||
}
|
||||
return pixels;
|
||||
};
|
||||
const before = render(0), during = render(1800);
|
||||
assert.notDeepEqual(before, during, 'the selected label actually moves');
|
||||
const decorationX = [110, 82, 108][i];
|
||||
const decoration = pixels => Array.from({ length: 60 }, (_, y) =>
|
||||
Array.from(pixels.slice(y * 140 + decorationX, y * 140 + 119))).flat();
|
||||
assert.deepEqual(decoration(before), decoration(during), 'right decoration never moves or gets overwritten');
|
||||
assert.ok(decoration(before).some(v => v > 100), 'the fixed decoration is visible');
|
||||
}
|
||||
});
|
||||
|
||||
test('SettingsPanel labels animate only in the focused column', async () => {
|
||||
const { SettingsPanelLayer } = load('app/ui/dashboard/settings-panel.ts', {
|
||||
'../../graphics/ui-fonts': { getDefaultSmallFont: () => font }, '../../graphics/image': { GrayImage },
|
||||
'../../graphics/textwrap': { wrapText: () => [] }, '../gestures': {}, '../layers': {},
|
||||
'../menu': menuModule, '../menu-core': require('../.test-build/app/ui/menu-core.js'),
|
||||
'../metrics': require('../.test-build/app/ui/metrics.js'), '../shell/shell': { shell: {} },
|
||||
});
|
||||
const layer = new SettingsPanelLayer([{ label: 'very long section label beyond column width',
|
||||
items: [{ label: 'very long option label beyond the right column width', onSelect() {} }] }]);
|
||||
const ctx = { stack: { getBaseSize: () => ({ width: 360, height: 100 }), isFocused: () => true } };
|
||||
const left = lists(layer.paint(ctx));
|
||||
assert.equal(left.length, 1);
|
||||
assert.ok(left[0].x < 150);
|
||||
await layer.handleInput({ type: 'click' }, ctx);
|
||||
const right = lists(layer.paint(ctx));
|
||||
assert.equal(right.length, 1);
|
||||
assert.ok(right[0].x > 150);
|
||||
});
|
||||
|
||||
test('common MenuLayer default row retains the full overflowing label', () => {
|
||||
const layer = new menuModule.MenuLayer(null, [{ label: 'abcdefghijklmnopZ', onSelect() {} }],
|
||||
{ x: 0, y: 0, width: 80, minHeight: 40, maxHeight: 50 });
|
||||
const image = layer.paint({ stack: { getBaseSize: () => ({ width: 80, height: 60 }), isFocused: () => true } }, () => new GrayImage(80, 60));
|
||||
assert.equal(lists(image).length, 1);
|
||||
});
|
||||
@@ -159,7 +159,7 @@ test('Music settings keeps toggles and selection when a new app arrives and supp
|
||||
'../graphics/textwrap': textwrap,
|
||||
'../graphics/ui-fonts': { getDefaultSmallFont: () => font },
|
||||
'../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'),
|
||||
'./menu-label': require('../.test-build/app/ui/menu-label.js'), './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'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback }, '../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
|
||||
};
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { loader } = require('./helpers/load-typescript.cjs');
|
||||
const graphics = require('../.test-build/app/graphics/image.js');
|
||||
const planes = require('../.test-build/app/graphics/plane.js');
|
||||
const { encodeShellScene } = require('../.test-build/app/graphics/shell-scene.js');
|
||||
const { readPresentation, paintPresentation } = require('../.test-build/app/graphics/presentation-wire.js');
|
||||
const { DrawOp } = require('../.test-build/app/graphics/display-list.js');
|
||||
|
||||
function fixture(width = 640, height = 480, retained = false) {
|
||||
const screen = { width, height, top: 0 };
|
||||
const load = loader({}, {
|
||||
'../graphics/image': graphics, '../graphics/plane': planes,
|
||||
'../graphics/screen-size': { screenWidth: () => screen.width, screenHeight: () => screen.height },
|
||||
'../native/frame-timings': { spanCurrent: (_name, action) => action() },
|
||||
'./gestures': { isDirectionalInput: () => false },
|
||||
'../../graphics/image': graphics, '../../graphics/plane': planes, '../gestures': {},
|
||||
'./geometry': {
|
||||
appViewportSize: () => ({ width: screen.width - 64, height: Math.min(288, screen.height) }),
|
||||
appViewportRect: () => ({ x: 32, y: screen.top, width: screen.width - 64, height: Math.min(288, screen.height) }),
|
||||
SHELL_OPAQUE_BLACK: 1,
|
||||
},
|
||||
});
|
||||
const { LayerStack, noopLayerActions } = load('app/ui/layers.ts');
|
||||
const { ShellModalLayer, modalRect } = load('app/ui/shell/modal-layer.ts');
|
||||
let lowerPaints = 0, innerSize, removed = 0;
|
||||
const background = { paint() {
|
||||
lowerPaints++;
|
||||
const image = new graphics.GrayImage(screen.width, screen.height);
|
||||
image.fillRect(0, 0, 24, 100, 170);
|
||||
return image;
|
||||
} };
|
||||
const stack = new LayerStack(background, noopLayerActions);
|
||||
const inner = {
|
||||
paint(ctx) {
|
||||
innerSize = ctx.stack.getBaseSize();
|
||||
const image = new graphics.GrayImage(innerSize.width, innerSize.height);
|
||||
image.fillRect(6, 6, 8, 8, 240);
|
||||
if (retained) image.drawMenuSelection(new graphics.GrayImage(20, 12, 255), 20, 18, 60, 120, 3, 0);
|
||||
return image;
|
||||
},
|
||||
handleInput() {},
|
||||
};
|
||||
const modal = new ShellModalLayer(inner, noopLayerActions, { removed() { removed++; } });
|
||||
return { screen, stack, modal, modalRect, innerSize: () => innerSize, lowerPaints: () => lowerPaints, removed: () => removed };
|
||||
}
|
||||
|
||||
// Real shell encoder and presentation decoder, replayed over a separate app
|
||||
// in native ShellScene.calls order: opaque cropped surface, then retained calls.
|
||||
function sceneFrame(f, appValue = 200) {
|
||||
const bytes = encodeShellScene(f.stack.paintUndimmed());
|
||||
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
||||
const frame = new graphics.GrayImage(f.screen.width, f.screen.height, appValue);
|
||||
const original = frame.pixels.slice(), layers = [];
|
||||
let p = 2;
|
||||
for (let i = 0; i < view.getUint16(0, true); i++) {
|
||||
const x = view.getInt16(p + 2, true), y = view.getInt16(p + 4, true);
|
||||
const width = view.getUint16(p + 6, true), height = view.getUint16(p + 8, true);
|
||||
const count = view.getUint16(p + 12, true);
|
||||
assert.ok(5 + Math.ceil(width / 2) * height <= 65536);
|
||||
assert.equal(view.getUint16(p + 10, true), 256, 'vector mask does not rely on zero dim keeping no halftone');
|
||||
const image = new graphics.GrayImage(width, height);
|
||||
image.pixels.set(bytes.subarray(p + 16, p + 16 + width * height));
|
||||
frame.bitBlt(image, x, y);
|
||||
p += 16 + width * height;
|
||||
const selections = [];
|
||||
for (let j = 0; j < count; j++) {
|
||||
const record = readPresentation(bytes, p);
|
||||
selections.push(record.selection);
|
||||
paintPresentation(frame.pixels, original, frame.width, frame.height, record.selection);
|
||||
p = record.end;
|
||||
}
|
||||
layers.push({ x, y, width, height, selections });
|
||||
}
|
||||
assert.equal(p + 2, bytes.length, 'complete scene decoded');
|
||||
return { frame, layers, bytes };
|
||||
}
|
||||
|
||||
test('G2 notification serializes through the production shell scene within one 64 KiB surface', () => {
|
||||
const f = fixture();
|
||||
f.stack.push(f.modal);
|
||||
const { layers } = sceneFrame(f);
|
||||
assert.equal(layers.length, 1);
|
||||
assert.deepEqual({ ...layers[0], selections: undefined }, { ...f.modalRect(), selections: undefined });
|
||||
assert.equal(f.lowerPaints(), 0, 'chrome must not enter the scene');
|
||||
const mask = layers[0].selections[0].displayList;
|
||||
assert.equal(mask.resources.length, 0, 'no full-screen image or image tiles');
|
||||
assert.ok(mask.calls.every(call => call.op === DrawOp.CLEAR && call.color === 0 && call.clip));
|
||||
});
|
||||
|
||||
test('notification omits chrome and blacks out a separate app until dismissed', () => {
|
||||
const f = fixture(), before = sceneFrame(f).frame;
|
||||
assert.equal(f.lowerPaints(), 1);
|
||||
f.stack.push(f.modal);
|
||||
const { frame, layers } = sceneFrame(f);
|
||||
assert.equal(f.lowerPaints(), 1);
|
||||
assert.equal(layers.length, 1);
|
||||
assert.equal(frame.getPixel(0, 0), 0);
|
||||
assert.equal(frame.getPixel(639, 479), 0);
|
||||
assert.ok(!frame.pixels.includes(200), 'margins hide separate app surface');
|
||||
assert.ok(!frame.pixels.includes(170), 'status bar and switcher hidden');
|
||||
assert.ok(frame.pixels.includes(240), 'notification remains visible');
|
||||
f.stack.pop();
|
||||
assert.equal(f.removed(), 1);
|
||||
const closed = sceneFrame(f);
|
||||
assert.deepEqual(closed.frame.pixels, before.pixels);
|
||||
assert.equal(closed.layers[0].selections.length, 0, 'dismiss removes blackout');
|
||||
});
|
||||
|
||||
test('notification mask follows resize, band position and restore without covering content', () => {
|
||||
const f = fixture();
|
||||
f.stack.push(f.modal);
|
||||
for (const [width, height, top] of [[640, 480, 0], [540, 220, 0], [640, 480, 192], [640, 480, 0]]) {
|
||||
Object.assign(f.screen, { width, height, top });
|
||||
const { frame, layers } = sceneFrame(f), rect = f.modalRect();
|
||||
assert.equal(frame.getPixel(width - 1, height - 1), 0);
|
||||
assert.equal(frame.getPixel(rect.x, rect.y), 110);
|
||||
assert.equal(frame.getPixel(rect.x + 2, rect.y + 2), 1, 'interior opaque black');
|
||||
assert.equal(frame.getPixel(rect.x + 10, rect.y + 10), 240);
|
||||
assert.ok(!frame.pixels.includes(200), 'no app pixels survive');
|
||||
assert.equal(layers[0].height, rect.height);
|
||||
assert.deepEqual({ ...f.innerSize() }, { width: rect.width - 8, height: rect.height - 8 });
|
||||
}
|
||||
});
|
||||
|
||||
test('notification retains inner menu presentations after blackout with correct offsets', () => {
|
||||
const f = fixture(640, 480, true);
|
||||
f.stack.push(f.modal);
|
||||
const { layers, frame } = sceneFrame(f), rect = f.modalRect();
|
||||
const { selections } = layers[0];
|
||||
assert.equal(selections.length, 2, 'mask and selection both cross real encoder');
|
||||
const row = selections[0];
|
||||
assert.ok(row.displayList, 'selection is retained, not a frozen raster');
|
||||
assert.equal(row.x, rect.x + 4 + 20);
|
||||
assert.equal(row.y, rect.y + 4 + 18);
|
||||
assert.equal(frame.getPixel(row.x + 10, row.y + 6), 240);
|
||||
assert.equal(frame.getPixel(0, 0), 0);
|
||||
});
|
||||
@@ -120,7 +120,7 @@ function ui(fontSize = 12) {
|
||||
'../native/notification-types': require('../.test-build/app/native/notification-types.js'),
|
||||
'../native/notification-access': { isNotificationListenerEnabled: () => true },
|
||||
'../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'),
|
||||
'./menu-label': require('../.test-build/app/ui/menu-label.js'), './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'), './animation-speed': require('../.test-build/app/ui/animation-speed.js'), '../native/settings-store': { getStringSetting: (_key, fallback) => fallback }, '../graphics/screen-size': { screenWidth: () => 640, screenHeight: () => 480 },
|
||||
'./gestures': {},
|
||||
|
||||
@@ -15,6 +15,7 @@ function fakeImageModule() {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.texts = [];
|
||||
this.draws = [];
|
||||
return new Proxy(this, { get: (target, key) => (key in target ? target[key] : () => {}) });
|
||||
}
|
||||
drawText(_font, _x, _y, text) { this.texts.push(text); }
|
||||
|
||||
Reference in new issue
Block a user