Watch
2
0
Fork
You've already forked raylib-cs
0

feat: html harness focuses the example and allows quick navigation with J/K instead.

This commit is contained in:
tiger tiger tiger 2026-07-29 20:23:36 +02:00
commit 77244ee648
No known key found for this signature in database
2 changed files with 38 additions and 1 deletions

View file

@ -151,9 +151,37 @@ for (const name of Host.GetExampleNames().split('\n').filter(n => n.length > 0))
opt.textContent = name;
select.appendChild(opt);
}
select.addEventListener('change', () => selectExample(select.value));
select.addEventListener('change', () => {
selectExample(select.value);
canvas.focus();
});
selectExample(select.value);
// J/K step through examples instead of arrow keys on the focused dropdown,
// which would otherwise fight with examples that read the arrow keys.
function stepExample(delta) {
const count = select.options.length;
if (count === 0) {
return;
}
select.selectedIndex = (select.selectedIndex + delta + count) % count;
selectExample(select.value);
canvas.focus();
}
document.addEventListener('keydown', (event) => {
if (event.repeat || event.target instanceof HTMLSelectElement) {
return;
}
if (event.code === 'KeyJ') {
stepExample(1);
} else if (event.code === 'KeyK') {
stepExample(-1);
}
});
setScaleMode(scaleMode, false);
// Drive raylib one frame per animation tick, paced to the example's target FPS here rather