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

+7 -1
View File
@@ -2,12 +2,18 @@
## 0.7.3 - Future ## 0.7.3 - Future
### Depth and Animation
* A new display-list system for glasses-side drawing, unlocking z-effects and animation
* Menus animate when changing selection and scrolling
* Depth effects for the window switcher, top bar, and modals
* Glanceboard has configurable distance
### Other Features ### Other Features
* Add tokens and faceclaw-input script, which allows using a CLI utility as an input device for the glasses * Add tokens and faceclaw-input script, which allows using a CLI utility as an input device for the glasses
* Navigate app: Add map-without-destination mode * Navigate app: Add map-without-destination mode
* Nightscout app: Glanceboard widget still shows out-of-bounds values when out of space * Nightscout app: Glanceboard widget still shows out-of-bounds values when out of space
* Glanceboard: Add distance setting
### iOS port: ### iOS port:
+1 -1
View File
@@ -26,7 +26,7 @@ export type FirmwareInfo = {
}; };
/** The Faceclaw firmware revision this build of the app needs. */ /** 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 FACECLAW_PREFIX = "Faceclaw/";
const LEGACY_PREFIX = "EVENCFW"; const LEGACY_PREFIX = "EVENCFW";
+8 -8
View File
@@ -19,7 +19,7 @@ export type FirmwarePatchSet = {
export const CFW_PATCH_SET: FirmwarePatchSet = { export const CFW_PATCH_SET: FirmwarePatchSet = {
"base": "g2_2.3.0.24.bin", "base": "g2_2.3.0.24.bin",
"baseSha256": "187ccf2bcc5c17a212106e8a376745511e8289c4232b634a7ea94b9bf25a0979", "baseSha256": "187ccf2bcc5c17a212106e8a376745511e8289c4232b634a7ea94b9bf25a0979",
"outputSha256": "8dbb39ad4acaf430e889ff98fe698ccb54d55c19d90a4d7053ce0fb804adb11b", "outputSha256": "0275d20b0e50cd8fccc2eb4209384cac93ff3ae22149ddcc70da4a375440c818",
"patches": [ "patches": [
{ {
"offset": 1045797, "offset": 1045797,
@@ -210,43 +210,43 @@ export const CFW_PATCH_SET: FirmwarePatchSet = {
{ {
"offset": 4537963, "offset": 4537963,
"old": "", "old": "",
"new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf80b5002a18bf10f0030301d186460ce000f1010c864600bf013a0ef8011b04d01cf003030cf1010cf6d1102a11d35ffa81fc4ff001330cfb03fc00bf103acef80cc0cef808c0cef804c04ef810cb0f2af4d8042a0bd35ffa81fc4ff001330cfb03fc00bf043a032a4ef804cbfad8002a08bf80bdaef10103013a03f8011ffbd180bd00bf2de9f04fc5b04ff64c484ef66c6b4ff29c591446cff6ff78ccf2ff0bc2f229094ff6ff75002701260d93cde90e0106e048f2a351c0f24501bff32f8f8847d9f800a0bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f04bfc002800f01a81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001f5145abd1bff35f8f49e8000121b159e8001f5145f8d0a1e70f99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847d9f80070bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f0e5fb002800f0b480414600bf42180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb942abd1bff35f8f49e8000121b159e8001fb942f8d0a1e7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f023810f9800285fd00e980778a7f11700022859d80f980c2840f00c810e9e7078b178084300f00681f0780138022800f20181b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f06f83172f40f08483002a40f0e880fe2800f07485812800f06685002840f07b8551ea030040f0db8000f0fabe04460020b047d8b104f51d7151e800afbaf1000f0bd1bff35f8f00bf41e80002002a7bd051e800afbaf1000ff6d00021bff32f8f0029bff35f8f6bd0824694e74ff0ff37bfe047f6df40c0f24f008047002701261197adf8487006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594549d04ff46d7006f003fb002842d0414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142add1bff35f8f49e8000159b159e8001fa142f8d0a3e706f5a971884726e7012189e700200e9999b10f9a8ab1097801f07f02b2f10b0418bf0124b2f11c0618bf01268a2924dc0b2926d01c2924d03fe00d9010a804f0c7f84ff0ff3701269df84900002810a818bf4ff0ff3704f08bf9054646b99df8480028b94af21f30c0f247004c3080470d98002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010746884797f8641119b997f80413384669b14ff0ff3742f6f760c0f2440000f5807150468847384645b0bde8f08f0d9010a8264004f086f80e98007800f07f041d2c00f07e0018bf1a2811d1d9f800100322cff680720a40b2f1005fbff35f8f0ad10a685a4504bf002281f8812303e0a4f115010129e9d90f2c0adc092c00f3cc80052c00f07882072c40f0f282002769e0142c00f37781102c00f07582112c40f0e7820f98022840f00b840e990878112840f006844878002840f0028445f64d50c0f24600804701284ff000077ff475af40f20830c0f210003590ff208df8d00044f25220c0f20100339040f2c960c0f248003446cde93677804798b148f27e30c2f2070000880122c1b264298df8cf2008d80721b0f5807f38bf03218df8cf108df8d00040f2d260adf8d800052035ae8df8da00f01d33a90522fff748fc4ff22507c0f247070120092132460c23b8470746264631e748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f04e844ff46d7006f0b4f9002800f04684414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d10121c0f800b081728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142aad1bff35f8f49e80001002900f00c8459e8001fa142f6d09ee70a2c00f0b9810b2c40f02682d9f800500320cff680702840b0f1005fbff35f8f41f059802868002758457ff4baaed5f870030c9642f68d46c0f244060028a5f8807318bfb0470021a5f8b013c5f8ac13c5f8681185f8661185f86411d5f86c01c5f8601185f86511c5f86c11c5f80013a5f86c1320b148f2a351c0f245018847d5f87802002818bf04f02df90024c5f87842d5f8680320b148f2a351c0f245018847c5f86843a5f86c43286ca5f8444040b1b047286c06f166018847002804bf002028644bf63940c0f251008047d9f800400320cff680702040b0f1005fbff35f8f2ad12068584527d194f877010027c4f8807188b149f25962c0f25902002044f2436184f8777190474ef6e378c0f25a08c04708f1bc008047d4f8840184f8707150b1b047d4f8840106f166018847002804bf0020c4f88401d9f800000321cff680710140b1f1005fbff35f8f40f00a860168594540f0068690f8a811002900f0fb8506f0c9fb00f0fdbd152c00f06b811Line truncated "new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf80b5002a18bf10f0030301d186460ce000f1010c864600bf013a0ef8011b04d01cf003030cf1010cf6d1102a11d35ffa81fc4ff001330cfb03fc00bf103acef80cc0cef808c0cef804c04ef810cb0f2af4d8042a0bd35ffa81fc4ff001330cfb03fc00bf043a032a4ef804cbfad8002a08bf80bdaef10103013a03f8011ffbd180bd00bf2de9f04fc5b04ff64c484ef66c6b4ff29c591446cff6ff78ccf2ff0bc2f229094ff6ff75002701260d93cde90e0106e048f2a351c0f24501bff32f8f8847d9f800a0bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f04bfc002800f01a81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001f5145abd1bff35f8f49e8000121b159e8001f5145f8d0a1e70f99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847d9f80070bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f0e5fb002800f0b480414600bf42180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb942abd1bff35f8f49e8000121b159e8001fb942f8d0a1e7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f023810f9800285fd00e980778a7f11700022859d80f980c2840f00c810e9e7078b178084300f00681f0780138022800f20181b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f06f83172f40f08483002a40f0e880fe2800f07485812800f06685002840f07b8551ea030040f0db8000f0fabe04460020b047d8b104f51d7151e800afbaf1000f0bd1bff35f8f00bf41e80002002a7bd051e800afbaf1000ff6d00021bff32f8f0029bff35f8f6bd0824694e74ff0ff37bfe047f6df40c0f24f008047002701261197adf8487006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594549d04ff46d7006f003fb002842d0414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142add1bff35f8f49e8000159b159e8001fa142f8d0a3e706f5a971884726e7012189e700200e9999b10f9a8ab1097801f07f02b2f10b0418bf0124b2f11c0618bf01268a2924dc0b2926d01c2924d03fe00d9010a804f0c7f84ff0ff3701269df84900002810a818bf4ff0ff3704f08bf9054646b99df8480028b94af21f30c0f247004c3080470d98002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010746884797f8641119b997f80413384669b14ff0ff3742f6f760c0f2440000f5807150468847384645b0bde8f08f0d9010a8264004f086f80e98007800f07f041d2c00f07e0018bf1a2811d1d9f800100322cff680720a40b2f1005fbff35f8f0ad10a685a4504bf002281f8812303e0a4f115010129e9d90f2c0adc092c00f3cc80052c00f07882072c40f0f282002769e0142c00f37781102c00f07582112c40f0e7820f98022840f00b840e990878112840f006844878002840f0028445f64d50c0f24600804701284ff000077ff475af40f20830c0f210003590ff208df8d00044f25220c0f20100339040f2c960c0f248003446cde93677804798b148f27e30c2f2070000880122c1b264298df8cf2008d80721b0f5807f38bf03218df8cf108df8d00040f2d260adf8d800052035ae8df8da00f01d33a90522fff748fc4ff22507c0f247070120092132460c23b8470746264631e748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f04e844ff46d7006f0b4f9002800f04684414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d10121c0f800b081728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142aad1bff35f8f49e80001002900f00c8459e8001fa142f6d09ee70a2c00f0b9810b2c40f02682d9f800500320cff680702840b0f1005fbff35f8f41f059802868002758457ff4baaed5f870030c9642f68d46c0f244060028a5f8807318bfb0470021a5f8b013c5f8ac13c5f8681185f8661185f86411d5f86c01c5f8601185f86511c5f86c11c5f80013a5f86c1320b148f2a351c0f245018847d5f87802002818bf04f02df90024c5f87842d5f8680320b148f2a351c0f245018847c5f86843a5f86c43286ca5f8444040b1b047286c06f166018847002804bf002028644bf63940c0f251008047d9f800400320cff680702040b0f1005fbff35f8f2ad12068584527d194f877010027c4f8807188b149f25962c0f25902002044f2436184f8777190474ef6e378c0f25a08c04708f1bc008047d4f8840184f8707150b1b047d4f8840106f166018847002804bf0020c4f88401d9f800000321cff680710140b1f1005fbff35f8f40f00a860168594540f0068690f8a811002900f0fb8506f0c9fb00f0fdbd152c00f06b811Line truncated
"desc": "append injected blobs to main-app payload" "desc": "append injected blobs to main-app payload"
}, },
{ {
"offset": 779123, "offset": 779123,
"old": "805a3900", "old": "805a3900",
"new": "5c4f3a00", "new": "384f3a00",
"desc": "main-app subheader payload size (ps)" "desc": "main-app subheader payload size (ps)"
}, },
{ {
"offset": 152, "offset": 152,
"old": "005b3900", "old": "005b3900",
"new": "dc4f3a00", "new": "b84f3a00",
"desc": "main-app TOC entry size (ps + 128)" "desc": "main-app TOC entry size (ps + 128)"
}, },
{ {
"offset": 779243, "offset": 779243,
"old": "805a3904", "old": "805a3904",
"new": "5c4f3a04", "new": "384f3a04",
"desc": "main-app preamble length (low 24 bits)" "desc": "main-app preamble length (low 24 bits)"
}, },
{ {
"offset": 779247, "offset": 779247,
"old": "effdbcea", "old": "effdbcea",
"new": "56bcf2ba", "new": "9218d6af",
"desc": "[5] ota/s200_firmware_ota.bin preamble crc32" "desc": "[5] ota/s200_firmware_ota.bin preamble crc32"
}, },
{ {
"offset": 156, "offset": 156,
"old": "c0c6322a", "old": "c0c6322a",
"new": "8dff7648", "new": "3ef62aed",
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)" "desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)"
}, },
{ {
"offset": 779127, "offset": 779127,
"old": "c0c6322a", "old": "c0c6322a",
"new": "8dff7648", "new": "3ef62aed",
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (subheader)" "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 - `IMAGE`: a local resource index, integer `x`/`y`, and `transparent`. Transparent
images skip pixels quantized to zero. Resources have `width`, `height`, and images skip pixels quantized to zero. Resources have `width`, `height`, and
gray8 `pixels`; a baked `GrayImage` can be used directly. gray8 `pixels`; a baked `GrayImage` can be used directly.
- `RECT_COPY`: a local resource index, integer source rectangle and destination - `RECT_COPY`: a local resource index, source rectangle and destination
`dx`/`dy`. `SCREEN` reads the uncomposed frame; its source coordinates are also `dx`/`dy`. Source x/y and `dx`/`dy` accept expressions (revision 29); the
relative to this list's placement. Each call may add its own `depth` to the source rectangle must stay inside the source at every time, or firmware
list's depth. A screen restore normally uses the negative of the list depth. 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 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 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 integer remainder, negation, explicit conversions, lerp, and the easing functions
in `ExprOp`. `ease()` defaults to smoothstep. Integers wrap at 32 bits; float in `ExprOp`. `ease()` defaults to smoothstep. Integers wrap at 32 bits; float
operations round to f32. The firmware's existing stack/error semantics apply. 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 `maximum.time()` returns `min(milliseconds since PRESENT, maximum)`. The existing
45 ms repaint timer remains active while this is below maximum. `E.elapsed()` is 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. 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 `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. TypeScript. There is no animated-menu tag or menu animation policy in Kotlin.
## Bridge framing ## 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), 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 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; 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 operands otherwise use their fixed-width fields, except rounded x/y and rect-copy
extended varints. Expressions use the firmware bytecode plus bridge-only 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. `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. 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 = ( 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.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.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 }; ) & { depth?: number };
export type DisplayList = { export type DisplayList = {
readonly resources: readonly ListImage[]; 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)); out.u8(integer(call.background, 0, 15)); out.u8(integer(call.border, 0, 16));
} else { } else {
if (call.resource !== SCREEN) integer(call.resource, 0, list.resources.length - 1); 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'); if (call.op === DrawOp.IMAGE && call.resource === SCREEN) throw new Error('Use rectCopy to read SCREEN');
out.u16(call.resource); out.u16(call.resource);
if (call.op === DrawOp.IMAGE) { out.i16(call.x); out.i16(call.y); out.u8(call.transparent ? 31 : 15); } if (call.op === DrawOp.IMAGE) { out.i16(call.x); out.i16(call.y); out.u8(call.transparent ? 31 : 15); }
else { 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(); 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() }); 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.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'); else throw new Error('Unsupported display-list call');
} }
if (r.offset !== length) throw new Error('Trailing display-list bytes'); if (r.offset !== length) throw new Error('Trailing display-list bytes');
@@ -121,8 +122,9 @@ export function paintDisplayList(output: Uint8Array, screen: Uint8Array, width:
} else { } else {
const source = c.resource === SCREEN ? { width, height, pixels: screen } : placed.displayList.resources[c.resource]; 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 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 at = (v: DrawValue) => evaluate(v, elapsed, presentTime).value;
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 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++) { 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; 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]); 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. */ /** Time already elapsed on this list's timeline when the next PRESENT happens. */
static elapsed(): DrawExpression<'i32'> { return new DrawExpression('i32', [ExprOp.ELAPSED]); } 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 duration = DrawExpression.i32(integer(durationMs, 1, 2147483647));
const elapsed = DrawExpression.elapsed().min(duration); const end = DrawExpression.i32(integer(delayMs + durationMs, 1, 2147483647));
return duration.sub(elapsed).max(DrawExpression.i32(0)).time() const elapsed = DrawExpression.elapsed().min(end);
.add(elapsed).toFloat().div(duration.toFloat()); 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)); } static decode(code: Uint8Array): DrawExpression<'i32'> { return new DrawExpression('i32', Array.from(code)); }
private binary(other: DrawExpression<T>, i: number, f: number): DrawExpression<T> { 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 { GrayImage } from "../graphics/image";
import { menuScrollList, type MenuScrollHighlight } from "../graphics/menu-scroll-list";
import type { InputEvent } from "./gestures"; import type { InputEvent } from "./gestures";
import { MenuHighlightMotion } from "./menu-highlight-motion"; 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. */ /** Selected-row fill while the menu owns input; the outline alone marks an unfocused menu's selection. */
export const MENU_HIGHLIGHT_FILL = 15; export const MENU_HIGHLIGHT_FILL = 15;
@@ -9,6 +11,8 @@ const SCROLLBAR_TRACK_VALUE = 30;
const SCROLLBAR_THUMB_VALUE = 120; const SCROLLBAR_THUMB_VALUE = 120;
const SCROLLBAR_WIDTH = 3; const SCROLLBAR_WIDTH = 3;
const SCROLLBAR_MIN_THUMB = 8; 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. */ /** A rectangle in image coordinates. */
export type MenuBox = { x: number; y: number; width: number; height: number }; 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 * 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 * 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 * are 0), replayed over the highlight. While a scroll animates, rows are
* or image.height, and never outside the rect. * 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; image: GrayImage;
item: T; 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 * Rows may vary in height and some may be unselectable; navigation skips
* those. Scrolling is pixel-based: the viewport moves the minimum needed to * 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 * keep the selection and its neighbors fully visible (just the selection
* never starts with a partially visible row. Rows that don't fully fit at * when they don't all fit), then aligns to a row top so the list never
* the bottom are not drawn. * 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> { export class Menu<T> {
private itemList: readonly T[]; private itemList: readonly T[];
@@ -89,6 +101,7 @@ export class Menu<T> {
private scrollY = 0; private scrollY = 0;
private lastBox: MenuBox | null = null; private lastBox: MenuBox | null = null;
private readonly motion = new MenuHighlightMotion(); private readonly motion = new MenuHighlightMotion();
private readonly scrollMotion = new MenuScrollMotion();
constructor(private readonly options: MenuOptions<T>) { constructor(private readonly options: MenuOptions<T>) {
this.itemList = options.items ?? []; this.itemList = options.items ?? [];
@@ -162,6 +175,7 @@ export class Menu<T> {
const next = this.nextSelectable(from, delta); const next = this.nextSelectable(from, delta);
if (next !== null) { if (next !== null) {
if (from !== null) this.motion.navigate(from, false); if (from !== null) this.motion.navigate(from, false);
this.scrollMotion.navigate(false);
this.selected = next; this.selected = next;
this.deselected = false; this.deselected = false;
return; return;
@@ -171,6 +185,7 @@ export class Menu<T> {
const wrapped = this.nextSelectable(null, delta); const wrapped = this.nextSelectable(null, delta);
if (wrapped !== null && wrapped !== from) { if (wrapped !== null && wrapped !== from) {
if (from !== null) this.motion.navigate(from, true); if (from !== null) this.motion.navigate(from, true);
this.scrollMotion.navigate(true);
this.selected = wrapped; this.selected = wrapped;
this.deselected = false; this.deselected = false;
} else if (from === null && this.lastBox) { } else if (from === null && this.lastBox) {
@@ -225,8 +240,13 @@ export class Menu<T> {
this.reconcile(); this.reconcile();
const layout = this.layout(box.width); const layout = this.layout(box.width);
this.ensureVisible(layout, box.height); 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 gap = this.options.rowGap ?? 0;
const highlight = this.options.highlight; const highlight = this.options.highlight;
let scrollHighlight: MenuScrollHighlight | undefined;
for (let index = 0; index < this.itemList.length; index++) { for (let index = 0; index < this.itemList.length; index++) {
const top = layout.tops[index]! - this.scrollY; const top = layout.tops[index]! - this.scrollY;
const height = layout.heights[index]! - gap; const height = layout.heights[index]! - gap;
@@ -238,15 +258,28 @@ export class Menu<T> {
const rowY = box.y + top; const rowY = box.y + top;
const item = this.itemList[index]!; const item = this.itemList[index]!;
if (selected && highlight !== false) { 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); 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 }); 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, background, MENU_HIGHLIGHT_STROKE,
image.drawMenuSelection(row, box.x, rowY, focused ? MENU_HIGHLIGHT_FILL : 0, MENU_HIGHLIGHT_STROKE,
highlight?.radius ?? 8, highlight?.depth ?? 0, animation); highlight?.radius ?? 8, highlight?.depth ?? 0, animation);
} else { } else {
this.options.draw({ image, item, index, x: box.x, y: rowY, width: box.width, height, selected, focused }); 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). */ /** 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); 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 { private isSelectable(index: number): boolean {
return this.options.isSelectable?.(this.itemList[index]!) ?? true; 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)); this.scrollY = Math.max(0, Math.min(this.maxScroll(layout, viewportHeight), this.scrollY));
return; return;
} }
const top = layout.tops[this.selected]!; const gap = this.options.rowGap ?? 0;
const bottom = top + layout.heights[this.selected]! - (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; let target = this.scrollY;
if (top < target) { if (wantTop < target) {
target = top; target = wantTop;
} else if (bottom > target + viewportHeight) { } else if (wantBottom > target + viewportHeight) {
// A row taller than the viewport shows from its top. // A row taller than the viewport shows from its top.
target = Math.min(top, bottom - viewportHeight); target = Math.min(top, wantBottom - viewportHeight);
// Snap to the first row that starts inside the viewport: the selected // Snap to the first row that starts inside the viewport: the wanted
// row still fits (its bottom is within viewportHeight of that top). // rows still fit (their bottom is within viewportHeight of that top).
for (let index = 0; index <= this.selected; index++) { for (let index = 0; index <= selected; index++) {
if (layout.tops[index]! >= target) { if (layout.tops[index]! >= target) {
target = layout.tops[index]!; target = layout.tops[index]!;
break; break;
+9 -3
View File
@@ -3,6 +3,11 @@ export type MenuHighlightAnimation = { dx: number; dy: number; startedAt: number
let nextToken = 1; 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. */ /** Eligibility is decided by menu navigation, before the display-list bridge. */
export class MenuHighlightMotion { export class MenuHighlightMotion {
private previous?: { index: number; scroll: number; x: number; y: number; width: number; height: number }; 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; 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; const previous = this.previous;
if (!previous || previous.index !== index || previous.scroll !== scroll || if (!previous || previous.index !== index || previous.scroll !== scroll ||
previous.x !== x || previous.y !== y || previous.width !== width || previous.height !== height) { previous.x !== x || previous.y !== y || previous.width !== width || previous.height !== height) {
@@ -25,8 +31,8 @@ export class MenuHighlightMotion {
fromY += this.animation.dy * remaining; fromY += this.animation.dy * remaining;
} }
const eligible = previous && previous.index !== index && this.fromIndex === previous.index && const eligible = previous && previous.index !== index && this.fromIndex === previous.index &&
previous.scroll === scroll && previous.width === width && previous.height === height; (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: nextToken++, durationMs: MENU_HIGHLIGHT_DURATION_MS } : undefined; 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.fromIndex = null;
this.previous = { index, scroll, x, y, width, height }; 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));
}
}
@@ -1,6 +1,6 @@
package com.faceclaw.app package com.faceclaw.app
/** Revision 28 wire grammar, shared by scene planning and the local renderer. */ /** Revision 29 wire grammar, shared by scene planning and the local renderer. */
object DrawProtocol { object DrawProtocol {
/** Mirrors g2flash/patches/zlib_glue.c. */ /** Mirrors g2flash/patches/zlib_glue.c. */
const val DRAW = CFW_MSG_DRAW_CALLS const val DRAW = CFW_MSG_DRAW_CALLS
@@ -97,14 +97,21 @@ object DrawProtocol {
fun rectCopy( fun rectCopy(
source: Int, x: Int, y: Int, width: Int, height: Int, dx: Int, dy: Int, source: Int, x: Int, y: Int, width: Int, height: Int, dx: Int, dy: Int,
target: Int? = null, depth: Int? = null, target: Int? = null, depth: Int? = null,
): ByteArray = rectCopy(source, DrawValue.Integer(x), DrawValue.Integer(y), width, height,
DrawValue.Integer(dx), DrawValue.Integer(dy), target, depth)
/** Revision 29: source and destination coordinates may be expressions; the source rect must stay in bounds. */
fun rectCopy(
source: Int, x: DrawValue, y: DrawValue, width: Int, height: Int, dx: DrawValue, dy: DrawValue,
target: Int? = null, depth: Int? = null,
): ByteArray = call(DRAW_OP_RECT_COPY, target, depth) { ): ByteArray = call(DRAW_OP_RECT_COPY, target, depth) {
writeU16(source) writeU16(source)
writeU16(x) writeExtended(x)
writeU16(y) writeExtended(y)
writeU16(width) writeU16(width)
writeU16(height) writeU16(height)
writeS16(dx) writeExtended(dx)
writeS16(dy) writeExtended(dy)
} }
/** Fill the whole target, ignoring depth. */ /** Fill the whole target, ignoring depth. */
@@ -256,13 +256,14 @@ class DisplayListRenderer(
private fun drawRectCopy(reader: DrawReader, target: Target, walk: Walk) { private fun drawRectCopy(reader: DrawReader, target: Target, walk: Walk) {
val id = reader.readU16() val id = reader.readU16()
val x = reader.readU16() val x = ExtendedVarint.evaluate(reader, walk.frame)
val y = reader.readU16() val y = ExtendedVarint.evaluate(reader, walk.frame)
val width = reader.readU16() val width = reader.readU16()
val height = reader.readU16() val height = reader.readU16()
val dx = reader.readS16() val dx = ExtendedVarint.evaluate(reader, walk.frame)
val dy = reader.readS16() val dy = ExtendedVarint.evaluate(reader, walk.frame)
reader.requireDone() reader.requireDone()
require(x >= 0 && y >= 0)
val source = when (id) { val source = when (id) {
DrawProtocol.SCREEN -> walk.screen DrawProtocol.SCREEN -> walk.screen
DrawProtocol.CURRENT -> target DrawProtocol.CURRENT -> target
@@ -272,7 +273,8 @@ class DisplayListRenderer(
} }
} }
require(width > 0 && height > 0 && x + width <= source.width && y + height <= source.height) require(width > 0 && height > 0 && x + width <= source.width && y + height <= source.height)
if (walk.apply) { // Mirrors the firmware's overflow guard before the depth shift.
if (walk.apply && dx in -65536..65536) {
// Snapshot the rectangle so overlapping copies have memmove semantics. // Snapshot the rectangle so overlapping copies have memmove semantics.
val copy = IntArray(width * height) { source.get(x + it % width, y + it / width) } val copy = IntArray(width * height) { source.get(x + it % width, y + it / width) }
for (i in copy.indices) target.put(dx + i % width, dy + i / width, copy[i]) for (i in copy.indices) target.put(dx + i % width, dy + i / width, copy[i])
@@ -21,7 +21,8 @@ class FrameDisplayList private constructor(
override fun translated(dx: Int, dy: Int) = FrameDisplayList(x + dx, y + dy, depth, resources, commands, startedAt, identity) override fun translated(dx: Int, dy: Int) = FrameDisplayList(x + dx, y + dy, depth, resources, commands, startedAt, identity)
private class Command(val op: Int, val depth: Int, val values: IntArray, private class Command(val op: Int, val depth: Int, val values: IntArray,
val x: DrawValue = DrawValue.Integer(0), val y: DrawValue = DrawValue.Integer(0)) val x: DrawValue = DrawValue.Integer(0), val y: DrawValue = DrawValue.Integer(0),
val dx: DrawValue = DrawValue.Integer(0), val dy: DrawValue = DrawValue.Integer(0))
override fun calls(ids: IntArray, nowMs: Long): List<ByteArray> { override fun calls(ids: IntArray, nowMs: Long): List<ByteArray> {
require(ids.size == resources.size) require(ids.size == resources.size)
@@ -34,9 +35,9 @@ class FrameDisplayList private constructor(
v[0], v[1], v[2], v[3], v[4], depth + c.depth) v[0], v[1], v[2], v[3], v[4], depth + c.depth)
DRAW_OP_IMAGE -> DrawProtocol.image(resource(v[0]), x + v[1], y + v[2], v[3], depth = depth + c.depth) DRAW_OP_IMAGE -> DrawProtocol.image(resource(v[0]), x + v[1], y + v[2], v[3], depth = depth + c.depth)
DRAW_OP_RECT_COPY -> DrawProtocol.rectCopy(resource(v[0]), DRAW_OP_RECT_COPY -> DrawProtocol.rectCopy(resource(v[0]),
v[1] + if (v[0] == DrawProtocol.SCREEN) x else 0, bind(c.x, elapsed, if (v[0] == DrawProtocol.SCREEN) x else 0),
v[2] + if (v[0] == DrawProtocol.SCREEN) y else 0, bind(c.y, elapsed, if (v[0] == DrawProtocol.SCREEN) y else 0),
v[3], v[4], x + v[5], y + v[6], depth = depth + c.depth) v[1], v[2], bind(c.dx, elapsed, x), bind(c.dy, elapsed, y), depth = depth + c.depth)
else -> error("Unsupported frame display-list opcode") else -> error("Unsupported frame display-list opcode")
} }
} }
@@ -115,11 +116,12 @@ class FrameDisplayList private constructor(
Command(op, d, intArrayOf(id, xx, yy, options)) Command(op, d, intArrayOf(id, xx, yy, options))
} }
DRAW_OP_RECT_COPY -> { DRAW_OP_RECT_COPY -> {
val id = resource(); val sx = r.readS16(); val sy = r.readS16() val id = resource(); val sx = value(); val sy = value()
val w = r.readU16(); val h = r.readU16(); val dx = r.readS16(); val dy = r.readS16() val w = r.readU16(); val h = r.readU16(); val dx = value(); val dy = value()
require(w in 1..640 && h in 1..480) require(w in 1..640 && h in 1..480)
require(id == DrawProtocol.SCREEN || sx >= 0 && sy >= 0) // Relative SCREEN sources may be negative until placement is added.
Command(op, d, intArrayOf(id, sx, sy, w, h, dx, dy)) require(id == DrawProtocol.SCREEN || listOf(sx, sy).all { it !is DrawValue.Integer || it.value >= 0 })
Command(op, d, intArrayOf(id, w, h), sx, sy, dx, dy)
} }
else -> error("Unsupported frame display-list opcode") else -> error("Unsupported frame display-list opcode")
} }
+2 -2
View File
@@ -27,11 +27,11 @@ const layers = load('app/ui/layers.ts', {
'../native/frame-timings': { spanCurrent: (_name, paint) => paint() }, '../native/frame-timings': { spanCurrent: (_name, paint) => paint() },
}); });
const menu = load('app/ui/menu.ts', { 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, '../graphics/image': graphics, '../graphics/ui-fonts': fonts, '../graphics/textwrap': textwrap,
'../util/numeric-util': numeric, './gestures': gestures, './metrics': load('app/ui/metrics.ts'), '../util/numeric-util': numeric, './gestures': gestures, './metrics': load('app/ui/metrics.ts'),
'./menu-core': load('app/ui/menu-core.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'),
}), }),
}); });
+1 -1
View File
@@ -6,7 +6,7 @@ const { GrayImage } = require('../.test-build/app/graphics/image.js');
const { encodePresentation } = require('../.test-build/app/graphics/presentation-wire.js'); const { encodePresentation } = require('../.test-build/app/graphics/presentation-wire.js');
// Also consumed by FrameDisplayListTest.kt: bridge bytes, not independently rebuilt native calls. // Also consumed by FrameDisplayListTest.kt: bridge bytes, not independently rebuilt native calls.
const MENU = '077e0000000300020002000200022a00000096000000010002000200ffffffff0200080000ff24017e30020000000001812c8001812c1611010017328001812c16103001812c3023414031ff24017c30020000000001812c8001812c1611010017328001812c16103001812c302341403102000200010001030400000000000000001f'; const MENU = '077e0000000300020002000200022a00000096000000010002000200ffffffff0200080000ff24017e30020000000001812c8001812c1611010017328001812c16103001812c3023414031ff24017c30020000000001812c8001812c1611010017328001812c16103001812c302341403102000200010001030400000000000000001f';
const MULTI = '074c000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f020000010000000000010001000200000002feffffffffff000001000100ffff0000'; const MULTI = '0744000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f0200000100000001000100020002feffffff7f00010001007f00';
test('extended integers agree with firmware widths and sign extension', () => { 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']]; 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() { @Test fun graphValidationPrecedesMutationAndCopyPreservesOverlap() {
val screen=hex("12345678"); val target=DisplayListRenderer.Target(screen,8,1) 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) DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(copy)),target)
assertContentEquals(hex("12123456"),screen) 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) val valid=DrawProtocol.bbox(hex("ffffffff"),4,0,0,8,1)
assertFails { DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(valid,byteArrayOf(99,0))),target) } assertFails { DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(valid,byteArrayOf(99,0))),target) }
assertContentEquals(hex("12123456"),screen) assertContentEquals(hex("12123456"),screen)
@@ -5,13 +5,13 @@ import kotlin.test.*
class DrawWireTest { class DrawWireTest {
private fun hex(value: String) = value.chunked(2).map { it.toInt(16).toByte() }.toByteArray() 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. // Literal vectors pin the firmware grammar independently of the reader.
val calls = listOf( val calls = listOf(
DrawProtocol.image(0x1234, -32768, 32767, 0x1f, target = 511, depth = -128) to DrawProtocol.image(0x1234, -32768, 32767, 0x1f, target = 511, depth = -128) to
"0403ff018034120080ff7f1f", "0403ff018034120080ff7f1f",
DrawProtocol.rectCopy(DrawProtocol.CURRENT, 1, 2, 3, 4, -5, -6) to DrawProtocol.rectCopy(DrawProtocol.CURRENT, 1, 2, 3, 4, -5, -6) to
"0200feff0100020003000400fbfffaff", "0200feff0102030004007b7a",
DrawProtocol.stockText(-1, 2, 15, hex("41c3a9")) to "0300ffff02000f0341c3a9", DrawProtocol.stockText(-1, 2, 15, hex("41c3a9")) to "0300ffff02000f0341c3a9",
DrawProtocol.text(511, -2, 3, 31, hex("01417f")) to "0500ff01feff03001f0301417f", DrawProtocol.text(511, -2, 3, 31, hex("01417f")) to "0500ff01feff03001f0301417f",
DrawProtocol.playList(511, depth = 127) to "07027fff01", DrawProtocol.playList(511, depth = 127) to "07027fff01",
@@ -29,11 +29,11 @@ class DrawWireTest {
assertContentEquals(hex("1bffff"), DrawProtocol.root(DrawProtocol.SCREEN)) assertContentEquals(hex("1bffff"), DrawProtocol.root(DrawProtocol.SCREEN))
val flat = DrawProtocol.screenCopy(640, 352) val flat = DrawProtocol.screenCopy(640, 352)
assertEquals(1, flat.size) assertEquals(1, flat.size)
assertContentEquals(hex("0200ffff000000008002600100000000"), flat[0]) assertContentEquals(hex("0200ffff0000800260010000"), flat[0])
val shifted = DrawProtocol.screenCopy(640, 352, -32) val shifted = DrawProtocol.screenCopy(640, 352, -32)
assertEquals(2, shifted.size) assertEquals(2, shifted.size)
assertContentEquals(hex("090000"), shifted[0]) assertContentEquals(hex("090000"), shifted[0])
assertContentEquals(hex("0202e0ffff000000008002600100000000"), shifted[1]) assertContentEquals(hex("0202e0ffff0000800260010000"), shifted[1])
} }
@Test fun optimizerFieldsAreReencodedAndOpaqueBytesArePreserved() { @Test fun optimizerFieldsAreReencodedAndOpaqueBytesArePreserved() {
@@ -43,7 +43,7 @@ class DrawWireTest {
"0fffff02001f0341c3a9" to "0300ffff02001f0341c3a9", "0fffff02001f0341c3a9" to "0300ffff02001f0341c3a9",
"030001020134120f10" to "010000000102010f10", "030001020134120f10" to "010000000102010f10",
"060f10" to "01000100000000080002000f10", "060f10" to "01000100000000080002000f10",
"090100020003000400fbfffaff" to "0200feff0100020003000400fbfffaff", "090100020003000400fbfffaff" to "0200feff0102030004007b7a",
) )
for ((record, expected) in records) { for ((record, expected) in records) {
val calls = DrawProtocol.fromOptimized(hex(record), 8, 2) val calls = DrawProtocol.fromOptimized(hex(record), 8, 2)
@@ -5,7 +5,8 @@ import kotlin.test.*
class FrameDisplayListTest { class FrameDisplayListTest {
// Golden records emitted by display-list-authoring.test.cjs. // Golden records emitted by display-list-authoring.test.cjs.
private val menu = "077e0000000300020002000200022a00000096000000010002000200ffffffff0200080000ff24017e30020000000001812c8001812c1611010017328001812c16103001812c3023414031ff24017c30020000000001812c8001812c1611010017328001812c16103001812c302341403102000200010001030400000000000000001f" 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 hex(s: String) = s.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
private fun read(bytes: ByteArray, now: Long = 1150): FrameDisplayList { private fun read(bytes: ByteArray, now: Long = 1150): FrameDisplayList {
val reader = ArrayByteReader(bytes) val reader = ArrayByteReader(bytes)
@@ -36,6 +37,25 @@ class FrameDisplayListTest {
assertNotEquals(read(hex(menu)).fingerprint, read(other).fingerprint) 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() { @Test fun localResourceIdsAreResolvedAndScreenCopiesStayAtScreenDepth() {
val list = read(hex(multi)).translated(10, 10) val list = read(hex(multi)).translated(10, 10)
val calls = list.calls(intArrayOf(41, 42), 1150) val calls = list.calls(intArrayOf(41, 42), 1150)
+21 -11
View File
@@ -11,8 +11,15 @@ function stringMenu(overrides = {}) {
const menu = new Menu({ const menu = new Menu({
items: ['a', 'b', 'c', 'd', 'e'], items: ['a', 'b', 'c', 'd', 'e'],
getHeight: () => 20, getHeight: () => 20,
draw: (args) => drawn.push({ item: args.item, x: args.x, y: args.y, width: args.width, height: args.height, draw: (args) => {
selected: args.selected, focused: args.focused, scratch: args.image !== drawn.image }), // 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 }), onSelect: (item, index) => selected.push({ item, index }),
onExitTop: () => exits.top++, onExitTop: () => exits.top++,
onExitBottom: () => exits.bottom++, onExitBottom: () => exits.bottom++,
@@ -23,7 +30,8 @@ function stringMenu(overrides = {}) {
const paint = (focused = true, box = { x: 10, y: 5, width: 80, height: 60 }) => { const paint = (focused = true, box = { x: 10, y: 5, width: 80, height: 60 }) => {
drawn.length = 0; drawn.length = 0;
menu.paint(image, box, focused); 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 }; 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]); 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(); const { menu, paint } = stringMenu();
await menu.handleInput({ type: 'scroll-down' }); 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' }); 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' }); await menu.handleInput({ type: 'scroll-down' });
assert.equal(menu.selectedIndex, 3); assert.equal(menu.selectedIndex, 3);
assert.deepEqual(paint().map((r) => r.item), ['b', 'c', 'd']); assert.deepEqual(paint().map((r) => r.item), ['c', 'd', 'e']);
assert.equal(menu.scrollTop, 20); assert.equal(menu.scrollTop, 40);
await menu.handleInput({ type: 'scroll-up' }); await menu.handleInput({ type: 'scroll-up' });
await menu.handleInput({ type: 'scroll-up' }); 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(); const { menu, paint } = stringMenu();
menu.select(3); menu.select(3);
paint(); 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']); menu.setItems(['x', 'y', 'z', 'd2', 'e2', 'f2', 'g2']);
assert.equal(menu.selectedIndex, 3); 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); menu.setItems(['x', 'y', 'z', 'w', 'v', 'u', 'd3'], 6);
assert.equal(menu.selectedIndex, 6); assert.equal(menu.selectedIndex, 6);
paint(); 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); menu.setItems(['only'], null);
assert.equal(menu.selectedIndex, null); assert.equal(menu.selectedIndex, null);
menu.setItems(['p', 'q'], 9); 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); menu.setItems(['a', 'b', 'c'], 2);
assert.deepEqual(paint().map((r) => r.item), ['a', 'b', 'c'], 'a row sorted in above stays visible'); assert.deepEqual(paint().map((r) => r.item), ['a', 'b', 'c'], 'a row sorted in above stays visible');
assert.equal(menu.scrollTop, 0); 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. // 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'] }); const long = stringMenu({ items: ['a', 'b', 'c', 'd', 'e', 'f', 'g'] });
long.menu.select(6); long.menu.select(6);
long.paint(); long.paint();
long.menu.select(4); long.menu.select(4);
long.paint(); 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); long.menu.setItems(['a', 'b', 'c', 'd', 'e'], 4);
assert.deepEqual(long.paint().map((r) => r.item), ['c', 'd', 'e']); assert.deepEqual(long.paint().map((r) => r.item), ['c', 'd', 'e']);
assert.equal(long.menu.scrollTop, 40); assert.equal(long.menu.scrollTop, 40);
+2 -2
View File
@@ -16,12 +16,12 @@ function load(file,modules) {
const font={lineHeight:12,ascent:10,descent:2,measureText:text=>text.length*4, 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);}}; 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',{ 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',{ const {MenuLayer}=load('app/ui/menu.ts',{
'../graphics/image':graphics,'../graphics/textwrap':{},'../graphics/ui-fonts':{getDefaultSmallFont:()=>font}, '../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':{}, '../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, './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}}); const {prepareFrameDraws}=load('app/graphics/glyph-wire.ts',{'./presentation-wire':wire,'../native/texture-atlas':{textureAtlasAvailable:()=>false}});
+146
View File
@@ -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);
});
+1 -1
View File
@@ -153,7 +153,7 @@ test('Music settings keeps toggles and selection when a new app arrives and supp
'../graphics/textwrap': textwrap, '../graphics/textwrap': textwrap,
'../graphics/ui-fonts': { getDefaultSmallFont: () => font }, '../graphics/ui-fonts': { getDefaultSmallFont: () => font },
'../util/numeric-util': { clamp: (n, lo, hi) => Math.max(lo, Math.min(hi, n)) }, '../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': {}, './metrics': load('app/ui/metrics.ts'), './gestures': {},
}; };
deps['./menu-core'] = load('app/ui/menu-core.ts', (name) => deps[name]); deps['./menu-core'] = load('app/ui/menu-core.ts', (name) => deps[name]);
+1 -1
View File
@@ -84,7 +84,7 @@ function ui(fontSize = 12) {
'../native/notification-sources': prefs, '../native/notification-sources': prefs,
'../native/notification-access': { isNotificationListenerEnabled: () => true }, '../native/notification-access': { isNotificationListenerEnabled: () => true },
'../util/render-freshness': { renderPassAllowsStaleData: () => false }, '../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'), './metrics': load('app/ui/metrics.ts'),
'./gestures': {}, './gestures': {},
}; };