forked from Blendman974/faceclaw
Animate scrolling in menus
This commit is contained in:
1 parent
915f155819
commit
c801bd5185
23 files changed
+514
-91
No files matched your search
@@ -27,11 +27,11 @@ const layers = load('app/ui/layers.ts', {
|
||||
'../native/frame-timings': { spanCurrent: (_name, paint) => paint() },
|
||||
});
|
||||
const menu = load('app/ui/menu.ts', {
|
||||
'./menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.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/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/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'),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ const { GrayImage } = require('../.test-build/app/graphics/image.js');
|
||||
const { encodePresentation } = require('../.test-build/app/graphics/presentation-wire.js');
|
||||
// Also consumed by FrameDisplayListTest.kt: bridge bytes, not independently rebuilt native calls.
|
||||
const MENU = '077e0000000300020002000200022a00000096000000010002000200ffffffff0200080000ff24017e30020000000001812c8001812c1611010017328001812c16103001812c3023414031ff24017c30020000000001812c8001812c1611010017328001812c16103001812c302341403102000200010001030400000000000000001f';
|
||||
const MULTI = '074c000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f020000010000000000010001000200000002feffffffffff000001000100ffff0000';
|
||||
const MULTI = '0744000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f0200000100000001000100020002feffffff7f00010001007f00';
|
||||
|
||||
test('extended integers agree with firmware widths and sign extension', () => {
|
||||
const vectors = [[63,'3f'],[-64,'40'],[64,'8040'],[-65,'bfbf'],[8191,'9fff'],[-8192,'a000'],[8192,'c02000'],[-8193,'dfdfff'],[1048575,'cfffff'],[-1048576,'d00000'],[1048576,'e0100000'],[-1048577,'efefffff'],[134217727,'e7ffffff'],[-134217728,'e8000000'],[134217728,'f008000000'],[2147483647,'f07fffffff'],[-2147483648,'f080000000']];
|
||||
|
||||
@@ -90,9 +90,20 @@ class DisplayListTest {
|
||||
}
|
||||
@Test fun graphValidationPrecedesMutationAndCopyPreservesOverlap() {
|
||||
val screen=hex("12345678"); val target=DisplayListRenderer.Target(screen,8,1)
|
||||
val copy=DrawProtocol.call(DRAW_OP_RECT_COPY,hex("feff000000000600010002000000"))
|
||||
val copy=DrawProtocol.call(DRAW_OP_RECT_COPY,hex("feff0000060001000200"))
|
||||
DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(copy)),target)
|
||||
assertContentEquals(hex("12123456"),screen)
|
||||
// Revision 29: an animated source row scrolls a raw strip; source bounds are checked each frame.
|
||||
val strip=mapOf(9 to DrawProtocol.rawImage(2,4,hex("11223344")))
|
||||
val scroll=DrawProtocol.rectCopy(9,DrawValue.Integer(0),DrawValue.animate(0,2,100),2,2,DrawValue.Integer(0),DrawValue.Integer(0))
|
||||
for ((elapsed,rows) in listOf(0L to "1122",100L to "3344",500L to "3344")) {
|
||||
val window=DisplayListRenderer.Target(ByteArray(2),2,2)
|
||||
val renderer=DisplayListRenderer(strip)
|
||||
renderer.execute(DrawProtocol.sequence(listOf(scroll)),window,elapsedMs=elapsed)
|
||||
assertContentEquals(hex(rows),window.bytes); assertEquals(elapsed<100,renderer.animationPending)
|
||||
}
|
||||
val past=DrawProtocol.rectCopy(9,0,3,2,2,0,0)
|
||||
assertFails { DisplayListRenderer(strip).execute(DrawProtocol.sequence(listOf(past)),DisplayListRenderer.Target(ByteArray(2),2,2)) }
|
||||
val valid=DrawProtocol.bbox(hex("ffffffff"),4,0,0,8,1)
|
||||
assertFails { DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(valid,byteArrayOf(99,0))),target) }
|
||||
assertContentEquals(hex("12123456"),screen)
|
||||
|
||||
@@ -5,13 +5,13 @@ import kotlin.test.*
|
||||
class DrawWireTest {
|
||||
private fun hex(value: String) = value.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
|
||||
|
||||
@Test fun encodersUseRevision28CoordinatesAndPreserveOtherWireBytes() {
|
||||
@Test fun encodersUseRevision29CoordinatesAndPreserveOtherWireBytes() {
|
||||
// Literal vectors pin the firmware grammar independently of the reader.
|
||||
val calls = listOf(
|
||||
DrawProtocol.image(0x1234, -32768, 32767, 0x1f, target = 511, depth = -128) to
|
||||
"0403ff018034120080ff7f1f",
|
||||
DrawProtocol.rectCopy(DrawProtocol.CURRENT, 1, 2, 3, 4, -5, -6) to
|
||||
"0200feff0100020003000400fbfffaff",
|
||||
"0200feff0102030004007b7a",
|
||||
DrawProtocol.stockText(-1, 2, 15, hex("41c3a9")) to "0300ffff02000f0341c3a9",
|
||||
DrawProtocol.text(511, -2, 3, 31, hex("01417f")) to "0500ff01feff03001f0301417f",
|
||||
DrawProtocol.playList(511, depth = 127) to "07027fff01",
|
||||
@@ -29,11 +29,11 @@ class DrawWireTest {
|
||||
assertContentEquals(hex("1bffff"), DrawProtocol.root(DrawProtocol.SCREEN))
|
||||
val flat = DrawProtocol.screenCopy(640, 352)
|
||||
assertEquals(1, flat.size)
|
||||
assertContentEquals(hex("0200ffff000000008002600100000000"), flat[0])
|
||||
assertContentEquals(hex("0200ffff0000800260010000"), flat[0])
|
||||
val shifted = DrawProtocol.screenCopy(640, 352, -32)
|
||||
assertEquals(2, shifted.size)
|
||||
assertContentEquals(hex("090000"), shifted[0])
|
||||
assertContentEquals(hex("0202e0ffff000000008002600100000000"), shifted[1])
|
||||
assertContentEquals(hex("0202e0ffff0000800260010000"), shifted[1])
|
||||
}
|
||||
|
||||
@Test fun optimizerFieldsAreReencodedAndOpaqueBytesArePreserved() {
|
||||
@@ -43,7 +43,7 @@ class DrawWireTest {
|
||||
"0fffff02001f0341c3a9" to "0300ffff02001f0341c3a9",
|
||||
"030001020134120f10" to "010000000102010f10",
|
||||
"060f10" to "01000100000000080002000f10",
|
||||
"090100020003000400fbfffaff" to "0200feff0100020003000400fbfffaff",
|
||||
"090100020003000400fbfffaff" to "0200feff0102030004007b7a",
|
||||
)
|
||||
for ((record, expected) in records) {
|
||||
val calls = DrawProtocol.fromOptimized(hex(record), 8, 2)
|
||||
|
||||
@@ -5,7 +5,8 @@ import kotlin.test.*
|
||||
class FrameDisplayListTest {
|
||||
// Golden records emitted by display-list-authoring.test.cjs.
|
||||
private val menu = "077e0000000300020002000200022a00000096000000010002000200ffffffff0200080000ff24017e30020000000001812c8001812c1611010017328001812c16103001812c3023414031ff24017c30020000000001812c8001812c1611010017328001812c16103001812c302341403102000200010001030400000000000000001f"
|
||||
private val multi = "074c000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f020000010000000000010001000200000002feffffffffff000001000100ffff0000"
|
||||
private val multi = "0744000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f0200000100000001000100020002feffffff7f00010001007f00"
|
||||
private val scroll = "0787000000030002000400020000070000009600000001000200040011223344556677880200020000000000ff220100300102300180f0800180f0161101001732800180f01610300180f0302341403102000200010008000000ff280101300100300180f0800180f0161101001732800180f01610300180f030234140310100170100160400020000000103"
|
||||
private fun hex(s: String) = s.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
|
||||
private fun read(bytes: ByteArray, now: Long = 1150): FrameDisplayList {
|
||||
val reader = ArrayByteReader(bytes)
|
||||
@@ -36,6 +37,25 @@ class FrameDisplayListTest {
|
||||
assertNotEquals(read(hex(menu)).fingerprint, read(other).fingerprint)
|
||||
}
|
||||
|
||||
@Test fun animatedCopySourcesRebindOnPresentAndDestinationsTranslate() {
|
||||
// Emitted by menu-scroll-animation.test.cjs: a menu strip scrolling from row 0 to row 2.
|
||||
val list = read(hex(scroll)).translated(10, 10)
|
||||
fun copy(elapsed: Long): List<Int> {
|
||||
val call = DrawReader(list.calls(intArrayOf(5), 1150).first())
|
||||
assertEquals(DRAW_OP_RECT_COPY, call.readU8())
|
||||
assertEquals(DRAW_FLAG_DEPTH, call.readU8())
|
||||
assertEquals(0, call.readS8())
|
||||
val frame = DrawEvaluation(elapsed)
|
||||
val values = listOf(call.readU16(), ExtendedVarint.evaluate(call, frame), ExtendedVarint.evaluate(call, frame),
|
||||
call.readU16(), call.readU16(), ExtendedVarint.evaluate(call, frame), ExtendedVarint.evaluate(call, frame))
|
||||
call.requireDone()
|
||||
return values + if (frame.animationPending) 1 else 0
|
||||
}
|
||||
// 150 of 240 ms elapsed before this PRESENT; the source row is not translated with the surface.
|
||||
assertEquals(listOf(5, 0, 1, 2, 2, 14, 12, 1), copy(0))
|
||||
assertEquals(listOf(5, 0, 2, 2, 2, 14, 12, 0), copy(90))
|
||||
}
|
||||
|
||||
@Test fun localResourceIdsAreResolvedAndScreenCopiesStayAtScreenDepth() {
|
||||
val list = read(hex(multi)).translated(10, 10)
|
||||
val calls = list.calls(intArrayOf(41, 42), 1150)
|
||||
|
||||
+21
-11
@@ -11,8 +11,15 @@ function stringMenu(overrides = {}) {
|
||||
const menu = new Menu({
|
||||
items: ['a', 'b', 'c', 'd', 'e'],
|
||||
getHeight: () => 20,
|
||||
draw: (args) => drawn.push({ item: args.item, x: args.x, y: args.y, width: args.width, height: args.height,
|
||||
selected: args.selected, focused: args.focused, scratch: args.image !== drawn.image }),
|
||||
draw: (args) => {
|
||||
// A scroll animation also draws rows into a strip taller than one row; only
|
||||
// the frame's rows are recorded. A strip's selected row uses a row scratch
|
||||
// like the static one, and an empty strip falls back to the static paint,
|
||||
// so paint() keeps one draw per row.
|
||||
if (args.image !== drawn.image && args.image.height !== args.height) return;
|
||||
drawn.push({ item: args.item, index: args.index, x: args.x, y: args.y, width: args.width, height: args.height,
|
||||
selected: args.selected, focused: args.focused, scratch: args.image !== drawn.image });
|
||||
},
|
||||
onSelect: (item, index) => selected.push({ item, index }),
|
||||
onExitTop: () => exits.top++,
|
||||
onExitBottom: () => exits.bottom++,
|
||||
@@ -23,7 +30,8 @@ function stringMenu(overrides = {}) {
|
||||
const paint = (focused = true, box = { x: 10, y: 5, width: 80, height: 60 }) => {
|
||||
drawn.length = 0;
|
||||
menu.paint(image, box, focused);
|
||||
return drawn.slice();
|
||||
const rows = new Map(drawn.map((row) => [row.index, row]));
|
||||
return [...rows.values()].sort((a, b) => a.index - b.index);
|
||||
};
|
||||
return { menu, paint, drawn, exits, selected, image };
|
||||
}
|
||||
@@ -49,14 +57,16 @@ test('rowGap shrinks the drawable box without changing the pitch', () => {
|
||||
assert.deepEqual(rows.map((r) => r.y), [0, 25, 45]);
|
||||
});
|
||||
|
||||
test('scrolling keeps the selection visible and aligns the viewport to a row top', async () => {
|
||||
test('scrolling keeps the selection and its neighbors visible and aligns the viewport to a row top', async () => {
|
||||
const { menu, paint } = stringMenu();
|
||||
await menu.handleInput({ type: 'scroll-down' });
|
||||
assert.deepEqual(paint().map((r) => r.item), ['a', 'b', 'c'], 'b and both neighbors already fit');
|
||||
await menu.handleInput({ type: 'scroll-down' });
|
||||
assert.deepEqual(paint().map((r) => r.item), ['b', 'c', 'd'], 'c reveals d below it');
|
||||
await menu.handleInput({ type: 'scroll-down' });
|
||||
assert.equal(menu.selectedIndex, 3);
|
||||
assert.deepEqual(paint().map((r) => r.item), ['b', 'c', 'd']);
|
||||
assert.equal(menu.scrollTop, 20);
|
||||
assert.deepEqual(paint().map((r) => r.item), ['c', 'd', 'e']);
|
||||
assert.equal(menu.scrollTop, 40);
|
||||
await menu.handleInput({ type: 'scroll-up' });
|
||||
await menu.handleInput({ type: 'scroll-up' });
|
||||
await menu.handleInput({ type: 'scroll-up' });
|
||||
@@ -144,14 +154,14 @@ test('setItems keeps the index by default, takes an explicit one, and holds the
|
||||
const { menu, paint } = stringMenu();
|
||||
menu.select(3);
|
||||
paint();
|
||||
assert.equal(menu.scrollTop, 20, 'row d sits at the bottom of the viewport');
|
||||
assert.equal(menu.scrollTop, 40, 'row d sits above its neighbor e at the bottom of the viewport');
|
||||
menu.setItems(['x', 'y', 'z', 'd2', 'e2', 'f2', 'g2']);
|
||||
assert.equal(menu.selectedIndex, 3);
|
||||
assert.equal(menu.scrollTop, 20);
|
||||
assert.equal(menu.scrollTop, 40);
|
||||
menu.setItems(['x', 'y', 'z', 'w', 'v', 'u', 'd3'], 6);
|
||||
assert.equal(menu.selectedIndex, 6);
|
||||
paint();
|
||||
assert.equal(menu.scrollTop, 80, 'row d3 (top 120) stays 40 px below the viewport top');
|
||||
assert.equal(menu.scrollTop, 80, 'row d3 (top 120) stays at the bottom, 40 px below the viewport top');
|
||||
menu.setItems(['only'], null);
|
||||
assert.equal(menu.selectedIndex, null);
|
||||
menu.setItems(['p', 'q'], 9);
|
||||
@@ -274,14 +284,14 @@ test('setItems never leaves the viewport scrolled past the end of the list', ()
|
||||
menu.setItems(['a', 'b', 'c'], 2);
|
||||
assert.deepEqual(paint().map((r) => r.item), ['a', 'b', 'c'], 'a row sorted in above stays visible');
|
||||
assert.equal(menu.scrollTop, 0);
|
||||
// The selected row at the top of a scrolled viewport loses the rows below it:
|
||||
// The selected row near the top of a scrolled viewport loses the rows below it:
|
||||
// keeping its on-screen position would leave a gap, so pull back to show the end.
|
||||
const long = stringMenu({ items: ['a', 'b', 'c', 'd', 'e', 'f', 'g'] });
|
||||
long.menu.select(6);
|
||||
long.paint();
|
||||
long.menu.select(4);
|
||||
long.paint();
|
||||
assert.equal(long.menu.scrollTop, 80, 'e is the top row');
|
||||
assert.equal(long.menu.scrollTop, 60, 'd, above e, is the top row');
|
||||
long.menu.setItems(['a', 'b', 'c', 'd', 'e'], 4);
|
||||
assert.deepEqual(long.paint().map((r) => r.item), ['c', 'd', 'e']);
|
||||
assert.equal(long.menu.scrollTop, 40);
|
||||
|
||||
@@ -16,12 +16,12 @@ 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/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'),
|
||||
});
|
||||
const {MenuLayer}=load('app/ui/menu.ts',{
|
||||
'../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'),
|
||||
'./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'),
|
||||
'./metrics':require('../.test-build/app/ui/metrics.js'),'./menu-core':menuCore,
|
||||
});
|
||||
const {prepareFrameDraws}=load('app/graphics/glyph-wire.ts',{'./presentation-wire':wire,'../native/texture-atlas':{textureAtlasAvailable:()=>false}});
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { Menu } = require('../.test-build/app/ui/menu-core.js');
|
||||
const { MENU_HIGHLIGHT_DURATION_MS } = require('../.test-build/app/ui/menu-highlight-motion.js');
|
||||
const { GrayImage } = require('../.test-build/app/graphics/image.js');
|
||||
const { DrawOp, encodeDisplayList, readDisplayList } = require('../.test-build/app/graphics/display-list.js');
|
||||
const { evaluate } = require('../.test-build/app/graphics/draw-expression.js');
|
||||
const { menuScrollList } = require('../.test-build/app/graphics/menu-scroll-list.js');
|
||||
const { encodePresentation } = require('../.test-build/app/graphics/presentation-wire.js');
|
||||
// Also consumed by FrameDisplayListTest.kt.
|
||||
const SCROLL = '0787000000030002000400020000070000009600000001000200040011223344556677880200020000000000ff220100300102300180f0800180f0161101001732800180f01610300180f0302341403102000200010008000000ff280101300100300180f0800180f0161101001732800180f01610300180f030234140310100170100160400020000000103';
|
||||
|
||||
const BOX = { x: 10, y: 5, width: 40, height: 60 };
|
||||
const ITEMS = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
|
||||
|
||||
function withClock(now, fn) {
|
||||
const original = Date.now;
|
||||
Date.now = () => now;
|
||||
try { return fn(); } finally { Date.now = original; }
|
||||
}
|
||||
|
||||
/** 20px rows whose ink ignores selection, so frames compare across selection changes. */
|
||||
function inkMenu(overrides = {}) {
|
||||
return new Menu({
|
||||
items: ITEMS,
|
||||
getHeight: () => 20,
|
||||
draw: ({ image, index, x, y }) => image.fillRect(x + 2 + index, y + 4, 6, 8, 200),
|
||||
...overrides,
|
||||
});
|
||||
}
|
||||
|
||||
function paint(menu, now, { box = BOX, background = 0, size = [64, 72] } = {}) {
|
||||
return withClock(now, () => {
|
||||
const image = new GrayImage(size[0], size[1], background);
|
||||
menu.paint(image, box, true);
|
||||
return image;
|
||||
});
|
||||
}
|
||||
|
||||
const scrollLists = (image) => image.draws
|
||||
.map((draw) => draw.presentation?.displayList)
|
||||
.filter((list) => list?.calls.some((call) => call.op === DrawOp.RECT_COPY));
|
||||
|
||||
/** What the glasses show at `at`, as 4-bit values. */
|
||||
function shown(image, at) {
|
||||
return withClock(at, () => Array.from(image.withDrawsBaked().pixels, (v) => Math.min(15, (v + 8) >> 4)));
|
||||
}
|
||||
|
||||
test('navigation that scrolls animates a strip covering both viewports', () => {
|
||||
const menu = inkMenu();
|
||||
menu.select(1);
|
||||
const before = paint(menu, 1000);
|
||||
assert.equal(menu.scrollTop, 0);
|
||||
menu.moveSelection(1);
|
||||
const moving = paint(menu, 2000);
|
||||
assert.equal(menu.scrollTop, 20, 'c scrolls d into view');
|
||||
const [list] = scrollLists(moving);
|
||||
assert.ok(list, 'a scroll display list is retained');
|
||||
const [strip] = list.resources;
|
||||
assert.equal(strip.height, 80, 'the strip spans the old and new viewports');
|
||||
assert.ok(strip.width < BOX.width, 'the strip is cropped to the ink columns');
|
||||
const copy = list.calls[0];
|
||||
assert.equal(copy.op, DrawOp.RECT_COPY);
|
||||
assert.equal(copy.height, BOX.height);
|
||||
assert.deepEqual(evaluate(copy.y, 0, 0), { value: 0, pending: true });
|
||||
assert.equal(evaluate(copy.y, MENU_HIGHLIGHT_DURATION_MS / 2, 0).value, 10);
|
||||
assert.deepEqual(evaluate(copy.y, MENU_HIGHLIGHT_DURATION_MS, 0), { value: 20, pending: false });
|
||||
assert.equal(list.calls[1].op, DrawOp.ROUNDED_RECT, 'the highlight is drawn over the copied rows');
|
||||
assert.equal(moving.draws.filter((draw) => draw.presentation && !draw.presentation.displayList?.calls.some((c) => c.op === DrawOp.RECT_COPY)).length, 0,
|
||||
'the selected row is in the strip, not a separate selection');
|
||||
|
||||
// First and last frames match the static paints on either side.
|
||||
assert.deepEqual(shown(moving, 2000), shown(before, 1000));
|
||||
const end = 2000 + MENU_HIGHLIGHT_DURATION_MS;
|
||||
const settled = paint(menu, end);
|
||||
assert.equal(scrollLists(settled).length, 0, 'the static paint takes over once the animation ends');
|
||||
assert.deepEqual(shown(moving, end), shown(settled, end));
|
||||
});
|
||||
|
||||
test('a second move during the scroll starts from the offset on screen', () => {
|
||||
const menu = inkMenu();
|
||||
menu.select(1);
|
||||
paint(menu, 1000);
|
||||
menu.moveSelection(1);
|
||||
paint(menu, 2000);
|
||||
menu.moveSelection(1);
|
||||
const image = paint(menu, 2000 + MENU_HIGHLIGHT_DURATION_MS / 2);
|
||||
assert.equal(menu.scrollTop, 40);
|
||||
const [list] = scrollLists(image);
|
||||
assert.equal(list.resources[0].height, 90, 'the strip starts at the current offset, 10');
|
||||
assert.equal(evaluate(list.calls[0].y, 0, 0).value, 0);
|
||||
assert.equal(evaluate(list.calls[0].y, MENU_HIGHLIGHT_DURATION_MS, 0).value, 30);
|
||||
});
|
||||
|
||||
test('wraps, programmatic moves, busy backgrounds and oversized strips snap', () => {
|
||||
const wrapping = inkMenu({ wrap: true });
|
||||
wrapping.select(6);
|
||||
paint(wrapping, 1000);
|
||||
wrapping.moveSelection(1);
|
||||
assert.equal(scrollLists(paint(wrapping, 2000)).length, 0, 'wrap');
|
||||
|
||||
const jumped = inkMenu();
|
||||
paint(jumped, 1000);
|
||||
jumped.select(5);
|
||||
assert.equal(scrollLists(paint(jumped, 2000)).length, 0, 'select()');
|
||||
|
||||
const busy = inkMenu();
|
||||
busy.select(1);
|
||||
paint(busy, 1000, { background: 100 });
|
||||
busy.moveSelection(1);
|
||||
const covered = paint(busy, 2000, { background: 100 });
|
||||
assert.equal(scrollLists(covered).length, 0, 'the opaque copy would hide the host background');
|
||||
assert.equal(covered.draws.filter((draw) => draw.presentation).length, 1, 'the selection is still drawn');
|
||||
|
||||
// 600px-wide rows: a 600x220 strip exceeds the 64 KiB resource limit unless cropped.
|
||||
const wide = (inkWidth) => {
|
||||
const menu = new Menu({ items: Array.from({ length: 20 }, (_, i) => i), getHeight: () => 20,
|
||||
draw: ({ image, x, y }) => image.fillRect(x, y + 4, inkWidth, 8, 200) });
|
||||
const options = { box: { x: 0, y: 0, width: 600, height: 200 }, size: [640, 240] };
|
||||
menu.select(8);
|
||||
paint(menu, 1000, options);
|
||||
menu.moveSelection(1);
|
||||
return scrollLists(paint(menu, 2000, options));
|
||||
};
|
||||
assert.equal(wide(600).length, 0, 'too large');
|
||||
assert.equal(wide(40).length, 1, 'narrow ink crops under the limit');
|
||||
assert.equal(wide(40)[0].resources[0].width, 40);
|
||||
});
|
||||
|
||||
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 list = menuScrollList(strip, 1, 0, 2, { from: 0, to: 2, startedAt: 1000, token: 7, durationMs: MENU_HIGHLIGHT_DURATION_MS },
|
||||
{ y: 0, width: 4, height: 2, radius: 0, background: 15, border: 45, animation: { dx: 0, dy: 1, startedAt: 1000, token: 7, durationMs: MENU_HIGHLIGHT_DURATION_MS } });
|
||||
const bytes = encodeDisplayList({ displayList: list, x: 3, y: 2, width: 4, height: 2, depth: 0 }, 1150);
|
||||
assert.equal(Buffer.from(bytes).toString('hex'), SCROLL);
|
||||
const { placed } = readDisplayList(bytes, 0, 1150);
|
||||
const [copy, box] = placed.displayList.calls;
|
||||
assert.equal(evaluate(copy.y, 150, 0).value, 1);
|
||||
assert.deepEqual(evaluate(copy.y, 150, 90), { value: 2, pending: false });
|
||||
assert.equal(copy.dx, 1);
|
||||
assert.equal(evaluate(box.y, 0, 0).value, 0, 'the highlight is clamped inside the viewport');
|
||||
|
||||
const image = new GrayImage(8, 8);
|
||||
image.drawDisplayList(list, 3, 2, 4, 2);
|
||||
assert.ok(encodePresentation(image.draws[0]).length > 0);
|
||||
});
|
||||
@@ -153,7 +153,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'),
|
||||
'./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'),
|
||||
'./metrics': load('app/ui/metrics.ts'), './gestures': {},
|
||||
};
|
||||
deps['./menu-core'] = load('app/ui/menu-core.ts', (name) => deps[name]);
|
||||
|
||||
@@ -84,7 +84,7 @@ function ui(fontSize = 12) {
|
||||
'../native/notification-sources': prefs,
|
||||
'../native/notification-access': { isNotificationListenerEnabled: () => true },
|
||||
'../util/render-freshness': { renderPassAllowsStaleData: () => false },
|
||||
'./menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.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'),
|
||||
'./metrics': load('app/ui/metrics.ts'),
|
||||
'./gestures': {},
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user