- commit
- 0412695c754df78aedc65e38c5cf93050cab3701
- parent
- bad5e49422c7a67ec95afc0811a2eb7575acd182
- author
- Dami <dami.etoile@gmail.com>
| M | src/ | 3 | ++- |
| M | tests/ | 15 | ++++++++++++++- |
@@ -87,7 +87,7 @@ export function drawStepCounter(ctx, value, x, y, options = {}) {
8787 export function drawInlineActions(ctx, items, centerX, y, options = {}) {8888 ctx.save();8989 ctx.font = "800 10px Recursive, monospace";90- const metrics = items.map(({ key, label }) => {90+ const metrics = items.map(({ key, label, action }) => {9191 const keyWidth = Math.max(24, ctx.measureText(key).width + 12);9292 ctx.font = "600 10px Recursive, monospace";9393 const labelWidth = ctx.measureText(label).width;@@ -95,6 +95,7 @@ export function drawInlineActions(ctx, items, centerX, y, options = {}) {
9595 return {9696 key,9797 label,98+ action,9899 keyWidth,99100 labelWidth,100101 width: keyWidth + 8 + labelWidth,@@ -1,6 +1,6 @@
11 import test from 'node:test';22 import assert from 'node:assert/strict';3-import { drawLedger } from '../src/render/stage-hud.js';3+import { drawInlineActions, drawLedger } from '../src/render/stage-hud.js';44 55 function context() {66 const calls = [];@@ -45,3 +45,16 @@ test('drawLedger falls back to settled rules when no frame ledger exists', () =>
4545 drawLedger(ctx, [{ text: 'MIAU IS YOU' }], 10, 20, 300);4646 assert.equal(ctx.calls.filter(call => call[0] === 'fillText').length, 6);4747 });48+49+test('drawInlineActions presses only the matching Win action keycap', () => {50+ const ctx = context();51+ drawInlineActions(ctx, [52+ { key: 'ENTER', label: 'continue', action: 'confirm' },53+ { key: 'Z', label: 'undo', action: 'undo' },54+ ], 160, 40, {55+ now: 30,56+ keycapPress: { action: 'confirm', startedAt: 0 },57+ });58+ // The pressed keycap loses its lip fill while the other keeps both faces.59+ assert.equal(ctx.calls.filter(call => call[0] === 'fillRect').length, 3);60+});