feat: html harness focuses the example and allows quick navigation with J/K instead.
This commit is contained in:
parent
dfc34997bc
commit
77244ee648
2 changed files with 38 additions and 1 deletions
|
|
@ -46,6 +46,14 @@
|
||||||
background: #000;
|
background: #000;
|
||||||
}
|
}
|
||||||
#status { color: #888; font-size: .85rem; margin: 0; }
|
#status { color: #888; font-size: .85rem; margin: 0; }
|
||||||
|
#hint { color: #888; font-size: .8rem; margin-left: .5rem; }
|
||||||
|
#hint kbd {
|
||||||
|
font-family: inherit;
|
||||||
|
background: #2c2c2c;
|
||||||
|
border: 1px solid #444;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 0 .3rem;
|
||||||
|
}
|
||||||
#error {
|
#error {
|
||||||
color: #ff6b6b;
|
color: #ff6b6b;
|
||||||
background: #3a1d1d;
|
background: #3a1d1d;
|
||||||
|
|
@ -67,6 +75,7 @@
|
||||||
<option value="native">Native (1x)</option>
|
<option value="native">Native (1x)</option>
|
||||||
<option value="fit">Fit</option>
|
<option value="fit">Fit</option>
|
||||||
</select>
|
</select>
|
||||||
|
<span id="hint"><kbd>J</kbd>/<kbd>K</kbd> next/previous example</span>
|
||||||
</div>
|
</div>
|
||||||
<div id="error" hidden>This example crashed — see the browser console for details. Select another example to continue.</div>
|
<div id="error" hidden>This example crashed — see the browser console for details. Select another example to continue.</div>
|
||||||
<div id="viewport">
|
<div id="viewport">
|
||||||
|
|
|
||||||
|
|
@ -151,8 +151,36 @@ for (const name of Host.GetExampleNames().split('\n').filter(n => n.length > 0))
|
||||||
opt.textContent = name;
|
opt.textContent = name;
|
||||||
select.appendChild(opt);
|
select.appendChild(opt);
|
||||||
}
|
}
|
||||||
select.addEventListener('change', () => selectExample(select.value));
|
select.addEventListener('change', () => {
|
||||||
selectExample(select.value);
|
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);
|
setScaleMode(scaleMode, false);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue