Animate scrolling in menus

This commit is contained in:
James Babcock committed 2026-09-24 11:04:10 -07:00
1 parent 915f155819
commit c801bd5185
23 files changed
+514 -91

No files matched your search

+1 -1
View File
@@ -26,7 +26,7 @@ export type FirmwareInfo = {
};
/** The Faceclaw firmware revision this build of the app needs. */
export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 28;
export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 29;
const FACECLAW_PREFIX = "Faceclaw/";
const LEGACY_PREFIX = "EVENCFW";
+8 -8
View File
@@ -19,7 +19,7 @@ export type FirmwarePatchSet = {
export const CFW_PATCH_SET: FirmwarePatchSet = {
"base": "g2_2.3.0.24.bin",
"baseSha256": "187ccf2bcc5c17a212106e8a376745511e8289c4232b634a7ea94b9bf25a0979",
"outputSha256": "8dbb39ad4acaf430e889ff98fe698ccb54d55c19d90a4d7053ce0fb804adb11b",
"outputSha256": "0275d20b0e50cd8fccc2eb4209384cac93ff3ae22149ddcc70da4a375440c818",
"patches": [
{
"offset": 1045797,
@@ -210,43 +210,43 @@ export const CFW_PATCH_SET: FirmwarePatchSet = {
{
"offset": 4537963,
"old": "",
"new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf80b5002a18bf10f0030301d186460ce000f1010c864600bf013a0ef8011b04d01cf003030cf1010cf6d1102a11d35ffa81fc4ff001330cfb03fc00bf103acef80cc0cef808c0cef804c04ef810cb0f2af4d8042a0bd35ffa81fc4ff001330cfb03fc00bf043a032a4ef804cbfad8002a08bf80bdaef10103013a03f8011ffbd180bd00bf2de9f04fc5b04ff64c484ef66c6b4ff29c591446cff6ff78ccf2ff0bc2f229094ff6ff75002701260d93cde90e0106e048f2a351c0f24501bff32f8f8847d9f800a0bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f04bfc002800f01a81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001f5145abd1bff35f8f49e8000121b159e8001f5145f8d0a1e70f99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847d9f80070bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f0e5fb002800f0b480414600bf42180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb942abd1bff35f8f49e8000121b159e8001fb942f8d0a1e7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f023810f9800285fd00e980778a7f11700022859d80f980c2840f00c810e9e7078b178084300f00681f0780138022800f20181b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f06f83172f40f08483002a40f0e880fe2800f07485812800f06685002840f07b8551ea030040f0db8000f0fabe04460020b047d8b104f51d7151e800afbaf1000f0bd1bff35f8f00bf41e80002002a7bd051e800afbaf1000ff6d00021bff32f8f0029bff35f8f6bd0824694e74ff0ff37bfe047f6df40c0f24f008047002701261197adf8487006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594549d04ff46d7006f003fb002842d0414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142add1bff35f8f49e8000159b159e8001fa142f8d0a3e706f5a971884726e7012189e700200e9999b10f9a8ab1097801f07f02b2f10b0418bf0124b2f11c0618bf01268a2924dc0b2926d01c2924d03fe00d9010a804f0c7f84ff0ff3701269df84900002810a818bf4ff0ff3704f08bf9054646b99df8480028b94af21f30c0f247004c3080470d98002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010746884797f8641119b997f80413384669b14ff0ff3742f6f760c0f2440000f5807150468847384645b0bde8f08f0d9010a8264004f086f80e98007800f07f041d2c00f07e0018bf1a2811d1d9f800100322cff680720a40b2f1005fbff35f8f0ad10a685a4504bf002281f8812303e0a4f115010129e9d90f2c0adc092c00f3cc80052c00f07882072c40f0f282002769e0142c00f37781102c00f07582112c40f0e7820f98022840f00b840e990878112840f006844878002840f0028445f64d50c0f24600804701284ff000077ff475af40f20830c0f210003590ff208df8d00044f25220c0f20100339040f2c960c0f248003446cde93677804798b148f27e30c2f2070000880122c1b264298df8cf2008d80721b0f5807f38bf03218df8cf108df8d00040f2d260adf8d800052035ae8df8da00f01d33a90522fff748fc4ff22507c0f247070120092132460c23b8470746264631e748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f04e844ff46d7006f0b4f9002800f04684414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d10121c0f800b081728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142aad1bff35f8f49e80001002900f00c8459e8001fa142f6d09ee70a2c00f0b9810b2c40f02682d9f800500320cff680702840b0f1005fbff35f8f41f059802868002758457ff4baaed5f870030c9642f68d46c0f244060028a5f8807318bfb0470021a5f8b013c5f8ac13c5f8681185f8661185f86411d5f86c01c5f8601185f86511c5f86c11c5f80013a5f86c1320b148f2a351c0f245018847d5f87802002818bf04f02df90024c5f87842d5f8680320b148f2a351c0f245018847c5f86843a5f86c43286ca5f8444040b1b047286c06f166018847002804bf002028644bf63940c0f251008047d9f800400320cff680702040b0f1005fbff35f8f2ad12068584527d194f877010027c4f8807188b149f25962c0f25902002044f2436184f8777190474ef6e378c0f25a08c04708f1bc008047d4f8840184f8707150b1b047d4f8840106f166018847002804bf0020c4f88401d9f800000321cff680710140b1f1005fbff35f8f40f00a860168594540f0068690f8a811002900f0fb8506f0c9fb00f0fdbd152c00f06b811Line truncated
"new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf80b5002a18bf10f0030301d186460ce000f1010c864600bf013a0ef8011b04d01cf003030cf1010cf6d1102a11d35ffa81fc4ff001330cfb03fc00bf103acef80cc0cef808c0cef804c04ef810cb0f2af4d8042a0bd35ffa81fc4ff001330cfb03fc00bf043a032a4ef804cbfad8002a08bf80bdaef10103013a03f8011ffbd180bd00bf2de9f04fc5b04ff64c484ef66c6b4ff29c591446cff6ff78ccf2ff0bc2f229094ff6ff75002701260d93cde90e0106e048f2a351c0f24501bff32f8f8847d9f800a0bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f04bfc002800f01a81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001f5145abd1bff35f8f49e8000121b159e8001f5145f8d0a1e70f99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847d9f80070bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f0e5fb002800f0b480414600bf42180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb942abd1bff35f8f49e8000121b159e8001fb942f8d0a1e7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f023810f9800285fd00e980778a7f11700022859d80f980c2840f00c810e9e7078b178084300f00681f0780138022800f20181b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f06f83172f40f08483002a40f0e880fe2800f07485812800f06685002840f07b8551ea030040f0db8000f0fabe04460020b047d8b104f51d7151e800afbaf1000f0bd1bff35f8f00bf41e80002002a7bd051e800afbaf1000ff6d00021bff32f8f0029bff35f8f6bd0824694e74ff0ff37bfe047f6df40c0f24f008047002701261197adf8487006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594549d04ff46d7006f003fb002842d0414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142add1bff35f8f49e8000159b159e8001fa142f8d0a3e706f5a971884726e7012189e700200e9999b10f9a8ab1097801f07f02b2f10b0418bf0124b2f11c0618bf01268a2924dc0b2926d01c2924d03fe00d9010a804f0c7f84ff0ff3701269df84900002810a818bf4ff0ff3704f08bf9054646b99df8480028b94af21f30c0f247004c3080470d98002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010746884797f8641119b997f80413384669b14ff0ff3742f6f760c0f2440000f5807150468847384645b0bde8f08f0d9010a8264004f086f80e98007800f07f041d2c00f07e0018bf1a2811d1d9f800100322cff680720a40b2f1005fbff35f8f0ad10a685a4504bf002281f8812303e0a4f115010129e9d90f2c0adc092c00f3cc80052c00f07882072c40f0f282002769e0142c00f37781102c00f07582112c40f0e7820f98022840f00b840e990878112840f006844878002840f0028445f64d50c0f24600804701284ff000077ff475af40f20830c0f210003590ff208df8d00044f25220c0f20100339040f2c960c0f248003446cde93677804798b148f27e30c2f2070000880122c1b264298df8cf2008d80721b0f5807f38bf03218df8cf108df8d00040f2d260adf8d800052035ae8df8da00f01d33a90522fff748fc4ff22507c0f247070120092132460c23b8470746264631e748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f04e844ff46d7006f0b4f9002800f04684414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d10121c0f800b081728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142aad1bff35f8f49e80001002900f00c8459e8001fa142f6d09ee70a2c00f0b9810b2c40f02682d9f800500320cff680702840b0f1005fbff35f8f41f059802868002758457ff4baaed5f870030c9642f68d46c0f244060028a5f8807318bfb0470021a5f8b013c5f8ac13c5f8681185f8661185f86411d5f86c01c5f8601185f86511c5f86c11c5f80013a5f86c1320b148f2a351c0f245018847d5f87802002818bf04f02df90024c5f87842d5f8680320b148f2a351c0f245018847c5f86843a5f86c43286ca5f8444040b1b047286c06f166018847002804bf002028644bf63940c0f251008047d9f800400320cff680702040b0f1005fbff35f8f2ad12068584527d194f877010027c4f8807188b149f25962c0f25902002044f2436184f8777190474ef6e378c0f25a08c04708f1bc008047d4f8840184f8707150b1b047d4f8840106f166018847002804bf0020c4f88401d9f800000321cff680710140b1f1005fbff35f8f40f00a860168594540f0068690f8a811002900f0fb8506f0c9fb00f0fdbd152c00f06b811Line truncated
"desc": "append injected blobs to main-app payload"
},
{
"offset": 779123,
"old": "805a3900",
"new": "5c4f3a00",
"new": "384f3a00",
"desc": "main-app subheader payload size (ps)"
},
{
"offset": 152,
"old": "005b3900",
"new": "dc4f3a00",
"new": "b84f3a00",
"desc": "main-app TOC entry size (ps + 128)"
},
{
"offset": 779243,
"old": "805a3904",
"new": "5c4f3a04",
"new": "384f3a04",
"desc": "main-app preamble length (low 24 bits)"
},
{
"offset": 779247,
"old": "effdbcea",
"new": "56bcf2ba",
"new": "9218d6af",
"desc": "[5] ota/s200_firmware_ota.bin preamble crc32"
},
{
"offset": 156,
"old": "c0c6322a",
"new": "8dff7648",
"new": "3ef62aed",
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)"
},
{
"offset": 779127,
"old": "c0c6322a",
"new": "8dff7648",
"new": "3ef62aed",
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (subheader)"
}
]
+13 -8
View File
@@ -32,10 +32,12 @@ Supported calls in this first pass:
- `IMAGE`: a local resource index, integer `x`/`y`, and `transparent`. Transparent
images skip pixels quantized to zero. Resources have `width`, `height`, and
gray8 `pixels`; a baked `GrayImage` can be used directly.
- `RECT_COPY`: a local resource index, integer source rectangle and destination
`dx`/`dy`. `SCREEN` reads the uncomposed frame; its source coordinates are also
relative to this list's placement. Each call may add its own `depth` to the
list's depth. A screen restore normally uses the negative of the list depth.
- `RECT_COPY`: a local resource index, source rectangle and destination
`dx`/`dy`. Source x/y and `dx`/`dy` accept expressions (revision 29); the
source rectangle must stay inside the source at every time, or firmware
rejects the list. `SCREEN` reads the uncomposed frame; its source coordinates
are also relative to this list's placement. Each call may add its own `depth`
to the list's depth. A screen restore normally uses the negative of the list depth.
Kotlin allocates/cache-pins all image resources, resolves the local indices, applies
surface placement, and includes the calls in the root firmware display list. The
@@ -48,7 +50,9 @@ the current firmware protocol; no firmware update is needed for this bridge chan
integer remainder, negation, explicit conversions, lerp, and the easing functions
in `ExprOp`. `ease()` defaults to smoothstep. Integers wrap at 32 bits; float
operations round to f32. The firmware's existing stack/error semantics apply.
Only rounded-rectangle x/y accept expressions in this first pass.
Rounded-rectangle x/y and rect-copy source/destination coordinates accept
expressions. `E.progress(duration, delay)` stays 0 for the first `delay` ms of
the timeline, so one list can run motions that started at different times.
`maximum.time()` returns `min(milliseconds since PRESENT, maximum)`. The existing
45 ms repaint timer remains active while this is below maximum. `E.elapsed()` is
@@ -64,7 +68,8 @@ exclude the changing elapsed duration. Without a timeline, raw `time()` expressi
start at each PRESENT. Native compilation strips the bridge-only elapsed opcode.
`menu-selection-list.ts` authors both the rounded highlight and the transparent row
image using this API. Navigation eligibility, duration, and easing remain in
image using this API. `menu-scroll-list.ts` authors a menu scroll: a viewport-sized
copy from a strip resource whose source y animates, then the highlight. Navigation eligibility, duration, and easing remain in
TypeScript. There is no animated-menu tag or menu animation policy in Kotlin.
## Bridge framing
@@ -73,8 +78,8 @@ Tag 7 is followed by a little-endian u32 byte length and a bounded body:
placement (i16 x/y, u16 width/height, i8 depth), timeline (u32 token/elapsed),
u16 resource count, gray8 images (u16 width/height followed by pixels), u16 call
count, then calls. Calls start with the firmware opcode and an i16 relative depth;
operands otherwise use their fixed-width fields, except rounded x/y which use
extended varints. Expressions use the firmware bytecode plus bridge-only
operands otherwise use their fixed-width fields, except rounded x/y and rect-copy
x/y/dx/dy which use extended varints. Expressions use the firmware bytecode plus bridge-only
`ELAPSED = 128`. Resource indices are local to this record, never firmware IDs.
Rect-copy source x/y are signed here to permit relative SCREEN coordinates.
+8 -6
View File
@@ -8,7 +8,7 @@ export type ListImage = { readonly width: number; readonly height: number; reado
export type ListCall = (
| { op: typeof DrawOp.ROUNDED_RECT; x: DrawValue; y: DrawValue; width: number; height: number; radius: number; background: number; border: number }
| { op: typeof DrawOp.IMAGE; resource: number; x: number; y: number; transparent: boolean }
| { op: typeof DrawOp.RECT_COPY; resource: number; x: number; y: number; width: number; height: number; dx: number; dy: number }
| { op: typeof DrawOp.RECT_COPY; resource: number; x: DrawValue; y: DrawValue; width: number; height: number; dx: DrawValue; dy: DrawValue }
) & { depth?: number };
export type DisplayList = {
readonly resources: readonly ListImage[];
@@ -53,12 +53,13 @@ export function encodeDisplayList(placed: PlacedDisplayList, now = Date.now()):
out.u8(integer(call.background, 0, 15)); out.u8(integer(call.border, 0, 16));
} else {
if (call.resource !== SCREEN) integer(call.resource, 0, list.resources.length - 1);
if (call.op === DrawOp.RECT_COPY && call.resource !== SCREEN && (call.x < 0 || call.y < 0)) throw new Error('Negative image source coordinate');
if (call.op === DrawOp.RECT_COPY && call.resource !== SCREEN && [call.x, call.y].some(v => typeof v === 'number' && v < 0)) throw new Error('Negative image source coordinate');
if (call.op === DrawOp.IMAGE && call.resource === SCREEN) throw new Error('Use rectCopy to read SCREEN');
out.u16(call.resource);
if (call.op === DrawOp.IMAGE) { out.i16(call.x); out.i16(call.y); out.u8(call.transparent ? 31 : 15); }
else {
out.i16(call.x); out.i16(call.y); out.u16(integer(call.width, 1, 640)); out.u16(integer(call.height, 1, 480)); out.i16(call.dx); out.i16(call.dy);
out.raw(encodeValue(call.x)); out.raw(encodeValue(call.y)); out.u16(integer(call.width, 1, 640)); out.u16(integer(call.height, 1, 480));
out.raw(encodeValue(call.dx)); out.raw(encodeValue(call.dy));
}
}
}
@@ -81,7 +82,7 @@ export function readDisplayList(bytes: Uint8Array, offset: number, now = Date.no
const op = r.u8(), depth = r.i16();
if (op === DrawOp.ROUNDED_RECT) calls.push({ op, depth, x: readValue(r), y: readValue(r), width: r.u16(), height: r.u16(), radius: r.u16(), background: r.u8(), border: r.u8() });
else if (op === DrawOp.IMAGE) calls.push({ op, depth, resource: r.u16(), x: r.i16(), y: r.i16(), transparent: (r.u8() & 16) !== 0 });
else if (op === DrawOp.RECT_COPY) calls.push({ op, depth, resource: r.u16(), x: r.i16(), y: r.i16(), width: r.u16(), height: r.u16(), dx: r.i16(), dy: r.i16() });
else if (op === DrawOp.RECT_COPY) calls.push({ op, depth, resource: r.u16(), x: readValue(r), y: readValue(r), width: r.u16(), height: r.u16(), dx: readValue(r), dy: readValue(r) });
else throw new Error('Unsupported display-list call');
}
if (r.offset !== length) throw new Error('Trailing display-list bytes');
@@ -121,8 +122,9 @@ export function paintDisplayList(output: Uint8Array, screen: Uint8Array, width:
} else {
const source = c.resource === SCREEN ? { width, height, pixels: screen } : placed.displayList.resources[c.resource];
const w = c.op === DrawOp.IMAGE ? source.width : c.width, h = c.op === DrawOp.IMAGE ? source.height : c.height;
const sx = c.op === DrawOp.IMAGE ? 0 : c.x + (c.resource === SCREEN ? placed.x : 0), sy = c.op === DrawOp.IMAGE ? 0 : c.y + (c.resource === SCREEN ? placed.y : 0);
const x = placed.x + (c.op === DrawOp.IMAGE ? c.x : c.dx) + shift, y = placed.y + (c.op === DrawOp.IMAGE ? c.y : c.dy);
const at = (v: DrawValue) => evaluate(v, elapsed, presentTime).value;
const sx = c.op === DrawOp.IMAGE ? 0 : at(c.x) + (c.resource === SCREEN ? placed.x : 0), sy = c.op === DrawOp.IMAGE ? 0 : at(c.y) + (c.resource === SCREEN ? placed.y : 0);
const x = placed.x + (c.op === DrawOp.IMAGE ? c.x : at(c.dx)) + shift, y = placed.y + (c.op === DrawOp.IMAGE ? c.y : at(c.dy));
for (let yy = 0; yy < h; yy++) for (let xx = 0; xx < w; xx++) {
if (x + xx < 0 || y + yy < 0 || x + xx >= width || y + yy >= height || sx + xx < 0 || sy + yy < 0 || sx + xx >= source.width || sy + yy >= source.height) continue;
const v = q(source.pixels[(sy + yy) * source.width + sx + xx]);
+10 -5
View File
@@ -59,12 +59,17 @@ export class DrawExpression<T extends 'i32' | 'f32'> {
}
/** Time already elapsed on this list's timeline when the next PRESENT happens. */
static elapsed(): DrawExpression<'i32'> { return new DrawExpression('i32', [ExprOp.ELAPSED]); }
/** A 0..1 timeline fraction that survives subsequent PRESENT clock resets. */
static progress(durationMs: number): DrawExpression<'f32'> {
/**
* A 0..1 timeline fraction that survives subsequent PRESENT clock resets.
* With a delay, it stays 0 for the first delayMs of the timeline.
*/
static progress(durationMs: number, delayMs = 0): DrawExpression<'f32'> {
const duration = DrawExpression.i32(integer(durationMs, 1, 2147483647));
const elapsed = DrawExpression.elapsed().min(duration);
return duration.sub(elapsed).max(DrawExpression.i32(0)).time()
.add(elapsed).toFloat().div(duration.toFloat());
const end = DrawExpression.i32(integer(delayMs + durationMs, 1, 2147483647));
const elapsed = DrawExpression.elapsed().min(end);
let total = end.sub(elapsed).max(DrawExpression.i32(0)).time().add(elapsed);
if (delayMs) total = total.sub(DrawExpression.i32(delayMs)).max(DrawExpression.i32(0));
return total.toFloat().div(duration.toFloat());
}
static decode(code: Uint8Array): DrawExpression<'i32'> { return new DrawExpression('i32', Array.from(code)); }
private binary(other: DrawExpression<T>, i: number, f: number): DrawExpression<T> {
+46
View File
@@ -0,0 +1,46 @@
import type { MenuHighlightAnimation } from '../ui/menu-highlight-motion';
import type { MenuScrollAnimation } from '../ui/menu-scroll-motion';
import { DrawExpression as E, type DrawValue } from './draw-expression';
import { DrawOp, type DisplayList, type ListCall, type ListImage } from './display-list';
export type MenuScrollHighlight = {
/** Final row top within the viewport. */
y: number;
width: number;
height: number;
radius: number;
/** Gray8, like drawMenuSelection. */
background: number;
border: number;
animation?: MenuHighlightAnimation;
};
/**
* A menu viewport scrolling over a pre-rendered strip. `strip` holds every
* row that is visible at any point of the scroll, starting at content offset
* `stripTop` and `stripX` pixels into the viewport. The copy's source row is
* the animated value; the highlight is max-blended over the copied rows,
* sliding on the same timeline and clamped inside the viewport.
*/
export function menuScrollList(strip: ListImage, stripX: number, stripTop: number, viewportHeight: number,
scroll: MenuScrollAnimation, highlight?: MenuScrollHighlight): DisplayList {
const eased = (durationMs: number, delayMs = 0) => E.progress(durationMs, delayMs).ease();
const sourceY: DrawValue = eased(scroll.durationMs)
.lerp(E.i32(scroll.from - stripTop).toFloat(), E.i32(scroll.to - stripTop).toFloat()).toInt();
const calls: ListCall[] = [
{ op: DrawOp.RECT_COPY, resource: 0, x: 0, y: sourceY, width: strip.width, height: viewportHeight, dx: stripX, dy: 0 },
];
if (highlight) {
const q = (n: number) => Math.min(15, (n + 8) >> 4);
const motion = highlight.animation;
let y: DrawValue = highlight.y;
if (motion?.dy) {
const delay = Math.max(0, motion.startedAt - scroll.startedAt);
y = eased(motion.durationMs, delay).lerp(E.i32(highlight.y + motion.dy).toFloat(), E.i32(highlight.y).toFloat()).toInt()
.max(E.i32(0)).min(E.i32(viewportHeight - highlight.height));
}
calls.push({ op: DrawOp.ROUNDED_RECT, x: 0, y, width: highlight.width, height: highlight.height, radius: highlight.radius,
background: q(highlight.background), border: q(highlight.border) });
}
return { resources: [strip], timeline: scroll, calls };
}
+118 -16
View File
@@ -1,6 +1,8 @@
import { GrayImage } from "../graphics/image";
import { menuScrollList, type MenuScrollHighlight } from "../graphics/menu-scroll-list";
import type { InputEvent } from "./gestures";
import { MenuHighlightMotion } from "./menu-highlight-motion";
import { MenuScrollMotion, type MenuScrollAnimation } from "./menu-scroll-motion";
/** Selected-row fill while the menu owns input; the outline alone marks an unfocused menu's selection. */
export const MENU_HIGHLIGHT_FILL = 15;
@@ -9,6 +11,8 @@ const SCROLLBAR_TRACK_VALUE = 30;
const SCROLLBAR_THUMB_VALUE = 120;
const SCROLLBAR_WIDTH = 3;
const SCROLLBAR_MIN_THUMB = 8;
/** Largest packed scroll strip, in bytes: the firmware's per-resource limit. */
const MAX_SCROLL_STRIP_BYTES = 65536;
/** A rectangle in image coordinates. */
export type MenuBox = { x: number; y: number; width: number; height: number };
@@ -17,8 +21,9 @@ export type MenuDrawArgs<T> = {
/**
* Draw into this image, inside the (x, y, width, height) rect. For the
* selected row this is a scratch image exactly the rect's size (so x and y
* are 0), replayed over the highlight. Never draw relative to image.width
* or image.height, and never outside the rect.
* are 0), replayed over the highlight. While a scroll animates, rows are
* also drawn into a strip image covering both viewports. Never draw
* relative to image.width or image.height, and never outside the rect.
*/
image: GrayImage;
item: T;
@@ -73,9 +78,16 @@ type MenuLayout = { tops: number[]; heights: number[]; total: number };
*
* Rows may vary in height and some may be unselectable; navigation skips
* those. Scrolling is pixel-based: the viewport moves the minimum needed to
* keep the selection fully visible, then aligns to a row top so the list
* never starts with a partially visible row. Rows that don't fully fit at
* the bottom are not drawn.
* keep the selection and its neighbors fully visible (just the selection
* when they don't all fit), then aligns to a row top so the list never
* starts with a partially visible row. Rows that don't fully fit at the
* bottom are not drawn.
*
* Navigation that scrolls (without wrapping) animates on the glasses: the
* rows visible before and after are drawn into one strip, and a display list
* slides a viewport-sized copy of it while the highlight moves on the same
* timeline. When the strip would be too large or the menu doesn't fit the
* assumptions below (see scrollStrip), the scroll snaps instead.
*/
export class Menu<T> {
private itemList: readonly T[];
@@ -89,6 +101,7 @@ export class Menu<T> {
private scrollY = 0;
private lastBox: MenuBox | null = null;
private readonly motion = new MenuHighlightMotion();
private readonly scrollMotion = new MenuScrollMotion();
constructor(private readonly options: MenuOptions<T>) {
this.itemList = options.items ?? [];
@@ -162,6 +175,7 @@ export class Menu<T> {
const next = this.nextSelectable(from, delta);
if (next !== null) {
if (from !== null) this.motion.navigate(from, false);
this.scrollMotion.navigate(false);
this.selected = next;
this.deselected = false;
return;
@@ -171,6 +185,7 @@ export class Menu<T> {
const wrapped = this.nextSelectable(null, delta);
if (wrapped !== null && wrapped !== from) {
if (from !== null) this.motion.navigate(from, true);
this.scrollMotion.navigate(true);
this.selected = wrapped;
this.deselected = false;
} else if (from === null && this.lastBox) {
@@ -225,8 +240,13 @@ export class Menu<T> {
this.reconcile();
const layout = this.layout(box.width);
this.ensureVisible(layout, box.height);
const now = Date.now();
const scroll = this.scrollMotion.paint(this.scrollY, box, now);
const strip = scroll ? this.scrollStrip(image, layout, box, focused, scroll) : null;
if (scroll && !strip) this.scrollMotion.cancel();
const gap = this.options.rowGap ?? 0;
const highlight = this.options.highlight;
let scrollHighlight: MenuScrollHighlight | undefined;
for (let index = 0; index < this.itemList.length; index++) {
const top = layout.tops[index]! - this.scrollY;
const height = layout.heights[index]! - gap;
@@ -238,15 +258,28 @@ export class Menu<T> {
const rowY = box.y + top;
const item = this.itemList[index]!;
if (selected && highlight !== false) {
const animation = this.motion.paint(index, this.scrollY, box.x, rowY, box.width, height, now, !!strip);
const background = focused ? MENU_HIGHLIGHT_FILL : 0;
if (strip) {
// The strip already holds this row's content; only the box is drawn over it.
scrollHighlight = { y: top, width: box.width, height, radius: highlight?.radius ?? 8,
background, border: MENU_HIGHLIGHT_STROKE, animation };
continue;
}
const row = new GrayImage(box.width, height, 0);
this.options.draw({ image: row, item, index, x: 0, y: 0, width: box.width, height, selected, focused });
const animation = this.motion.paint(index, this.scrollY, box.x, rowY, box.width, height, Date.now());
image.drawMenuSelection(row, box.x, rowY, focused ? MENU_HIGHLIGHT_FILL : 0, MENU_HIGHLIGHT_STROKE,
image.drawMenuSelection(row, box.x, rowY, background, MENU_HIGHLIGHT_STROKE,
highlight?.radius ?? 8, highlight?.depth ?? 0, animation);
} else {
this.options.draw({ image, item, index, x: box.x, y: rowY, width: box.width, height, selected, focused });
}
}
// The rows painted above stay underneath: once the animation ends, the
// strip's final frame and the static paint are pixel-identical.
if (strip && scroll) {
image.drawDisplayList(menuScrollList(strip.image, strip.x, strip.top, box.height, scroll, scrollHighlight),
box.x, box.y, box.width, box.height, 0);
}
}
/** Draw a vertical scrollbar for the last painted box (no-op unless the content overflows it). */
@@ -262,6 +295,65 @@ export class Menu<T> {
image.fillRect(x, y + (((height - thumbHeight) * fraction) | 0), SCROLLBAR_WIDTH, thumbHeight, SCROLLBAR_THUMB_VALUE);
}
/**
* Render every row visible at either end of the scroll into one strip, or
* return null to snap. Its final frame must match the static paint, so
* rows the static paint hides (partial ones at the bottom) are left out of
* the part the new viewport shows. The strip copy is opaque, so this also
* requires a black background under the menu, a selected row that fits,
* and a highlight at the menu's own depth.
*/
private scrollStrip(image: GrayImage, layout: MenuLayout, box: MenuBox, focused: boolean,
scroll: MenuScrollAnimation): { image: GrayImage; x: number; top: number } | null {
const highlight = this.options.highlight;
if (highlight !== false && (highlight?.depth ?? 0) !== 0) return null;
const gap = this.options.rowGap ?? 0;
const selected = this.selected;
if (selected !== null && layout.tops[selected]! + layout.heights[selected]! - gap - scroll.to > box.height) return null;
const top = Math.min(scroll.from, scroll.to);
const bottom = Math.max(scroll.from, scroll.to) + box.height;
const strip = new GrayImage(box.width, bottom - top, 0);
for (let index = 0; index < this.itemList.length; index++) {
const rowTop = layout.tops[index]!;
const height = layout.heights[index]! - gap;
const rowBottom = rowTop + height;
const shownAfter = rowTop >= scroll.to && rowBottom <= scroll.to + box.height;
const outsideAfter = rowBottom <= scroll.to || rowTop >= scroll.to + box.height;
if (!shownAfter && !(outsideAfter && rowTop >= top && rowBottom <= bottom)) continue;
const item = this.itemList[index]!;
const y = rowTop - top;
const isSelected = index === selected;
if (isSelected && highlight !== false) {
// Clip like the static selected row, which is drawn in a scratch image.
const row = new GrayImage(box.width, height, 0);
this.options.draw({ image: row, item, index, x: 0, y: 0, width: box.width, height, selected: true, focused });
strip.bitBlt(row.withDrawsBaked(), 0, y, { transparentZero: true });
} else {
this.options.draw({ image: strip, item, index, x: 0, y, width: box.width, height, selected: isSelected, focused });
}
}
// Crop to the columns with ink; the static paint shows the rest unchanged.
const baked = strip.withDrawsBaked();
let left = baked.width, right = -1;
for (let y = 0; y < baked.height; y++) {
const row = y * baked.width;
for (let x = 0; x < left; x++) if (baked.pixels[row + x]! >= 8) { left = x; break; }
for (let x = baked.width - 1; x > right; x--) if (baked.pixels[row + x]! >= 8) { right = x; break; }
}
if (right < left) return null;
const width = right - left + 1;
if (5 + Math.ceil(width / 2) * baked.height > MAX_SCROLL_STRIP_BYTES) return null;
// Whatever the host drew under the copied columns would be covered.
for (let y = box.y; y < box.y + box.height; y++) {
for (let x = box.x + left; x <= box.x + right; x++) {
if (x >= 0 && y >= 0 && x < image.width && y < image.height && image.pixels[y * image.width + x]! >= 8) return null;
}
}
const cropped = new GrayImage(width, baked.height, 0);
cropped.bitBlt(baked, -left, 0);
return { image: cropped, x: left, top };
}
private isSelectable(index: number): boolean {
return this.options.isSelectable?.(this.itemList[index]!) ?? true;
}
@@ -319,17 +411,27 @@ export class Menu<T> {
this.scrollY = Math.max(0, Math.min(this.maxScroll(layout, viewportHeight), this.scrollY));
return;
}
const top = layout.tops[this.selected]!;
const bottom = top + layout.heights[this.selected]! - (this.options.rowGap ?? 0);
const gap = this.options.rowGap ?? 0;
const selected = this.selected;
const top = layout.tops[selected]!;
const bottom = top + layout.heights[selected]! - gap;
// Keep the neighbors in view too when all three fit, so the user sees
// what the next step will reach.
const contextTop = selected > 0 ? layout.tops[selected - 1]! : top;
const contextBottom = selected + 1 < this.itemList.length
? layout.tops[selected + 1]! + layout.heights[selected + 1]! - gap : bottom;
const fits = contextBottom - contextTop <= viewportHeight;
const wantTop = fits ? contextTop : top;
const wantBottom = fits ? contextBottom : bottom;
let target = this.scrollY;
if (top < target) {
target = top;
} else if (bottom > target + viewportHeight) {
if (wantTop < target) {
target = wantTop;
} else if (wantBottom > target + viewportHeight) {
// A row taller than the viewport shows from its top.
target = Math.min(top, bottom - viewportHeight);
// Snap to the first row that starts inside the viewport: the selected
// row still fits (its bottom is within viewportHeight of that top).
for (let index = 0; index <= this.selected; index++) {
target = Math.min(top, wantBottom - viewportHeight);
// Snap to the first row that starts inside the viewport: the wanted
// rows still fit (their bottom is within viewportHeight of that top).
for (let index = 0; index <= selected; index++) {
if (layout.tops[index]! >= target) {
target = layout.tops[index]!;
break;
+9 -3
View File
@@ -3,6 +3,11 @@ export type MenuHighlightAnimation = { dx: number; dy: number; startedAt: number
let nextToken = 1;
/** A fresh display-list timeline token, shared by all menu animations. */
export function nextAnimationToken(): number {
return nextToken++;
}
/** Eligibility is decided by menu navigation, before the display-list bridge. */
export class MenuHighlightMotion {
private previous?: { index: number; scroll: number; x: number; y: number; width: number; height: number };
@@ -13,7 +18,8 @@ export class MenuHighlightMotion {
this.fromIndex = wrapped ? null : from;
}
paint(index: number, scroll: number, x: number, y: number, width: number, height: number, now: number): MenuHighlightAnimation | undefined {
/** `scrolling`: the scroll change since the last paint is itself animated, so the highlight may slide across it. */
paint(index: number, scroll: number, x: number, y: number, width: number, height: number, now: number, scrolling = false): MenuHighlightAnimation | undefined {
const previous = this.previous;
if (!previous || previous.index !== index || previous.scroll !== scroll ||
previous.x !== x || previous.y !== y || previous.width !== width || previous.height !== height) {
@@ -25,8 +31,8 @@ export class MenuHighlightMotion {
fromY += this.animation.dy * remaining;
}
const eligible = previous && previous.index !== index && this.fromIndex === previous.index &&
previous.scroll === scroll && previous.width === width && previous.height === height;
this.animation = eligible ? { dx: Math.round(fromX - x), dy: Math.round(fromY - y), startedAt: now, token: nextToken++, durationMs: MENU_HIGHLIGHT_DURATION_MS } : undefined;
(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;
this.previous = { index, scroll, x, y, width, height };
}
+53
View File
@@ -0,0 +1,53 @@
import { MENU_HIGHLIGHT_DURATION_MS, nextAnimationToken } from "./menu-highlight-motion";
/** Longest scroll, in pixels, that animates; longer jumps snap. */
export const MAX_ANIMATED_SCROLL = 96;
/** A viewport moving from content offset `from` to `to`, on the same clock as the highlight. */
export type MenuScrollAnimation = { from: number; to: number; startedAt: number; token: number; durationMs: number };
type Box = { x: number; y: number; width: number; height: number };
/**
* Tracks the painted scroll offset. Only a change caused by non-wrapping
* navigation animates; programmatic scrolls, item edits and geometry changes
* snap. A scroll during an animation starts from the offset on screen now.
*/
export class MenuScrollMotion {
private previous?: { scroll: number; box: Box };
private navigated = false;
private animation?: MenuScrollAnimation;
navigate(wrapped: boolean): void {
this.navigated = !wrapped;
}
/** 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 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;
this.animation = eligible
? { from, to: scroll, startedAt: now, token: nextAnimationToken(), durationMs: MENU_HIGHLIGHT_DURATION_MS }
: undefined;
this.previous = { scroll, box: { ...box } };
}
this.navigated = false;
return this.animation && now - this.animation.startedAt < this.animation.durationMs ? this.animation : undefined;
}
/** Cancel an animation in flight, e.g. when it cannot be drawn; the next change snaps from `settled`. */
cancel(): void {
this.animation = undefined;
}
private offsetAt(settled: number, now: number): number {
const animation = this.animation;
if (!animation) return settled;
const t = Math.max(0, Math.min(1, (now - animation.startedAt) / animation.durationMs));
return Math.round(animation.from + (animation.to - animation.from) * t * t * (3 - 2 * t));
}
}