lazy-widgets
Version:
Typescript retained mode GUI for the HTML canvas API
58 lines • 2.05 kB
JavaScript
import { GlyphVirtualKey } from './GlyphVirtualKey.js';
import { DynMsg } from '../../core/Strings.js';
import { Row } from '../Row.js';
import { filterIDFromProperties } from '../../helpers/filterIDFromProperties.js';
/**
* A {@link Row} of {@link VirtualKey | virtual keys}. Generates given a
* template.
*
* @category Widget
*/
export class VirtualKeyRow extends Row {
/**
* @param rowTemplate - Template for this row of virtual keys.
* @param keyContext - The {@link KeyContext} to be shared among all virtual keys in this row.
*/
constructor(rowTemplate, keyContext, properties) {
super([], properties);
const propertiesNoID = filterIDFromProperties(properties);
for (const entry of rowTemplate) {
if (typeof entry === 'function') {
// Entry is in template function format
const templateFunction = entry;
this.add(templateFunction(keyContext, propertiesNoID));
}
else if (typeof entry[0] === 'string' && typeof entry[1] === 'string') {
// Entry is in multiple glyphs format
const glyphs = entry[0];
const altGlyphs = entry[1];
for (let i = 0; i < glyphs.length; i++) {
let altGlyph = null;
if (i < altGlyphs.length) {
altGlyph = altGlyphs[i];
}
this.add(new GlyphVirtualKey(glyphs[i], altGlyph, keyContext, propertiesNoID));
}
}
else {
throw new Error(DynMsg.INVALID_KB_ROW_TEMPLATE(entry));
}
}
}
}
VirtualKeyRow.autoXML = {
name: 'virtual-key-row',
inputConfig: [
{
name: 'row-template',
mode: 'value',
validator: 'array',
},
{
name: 'key-context',
mode: 'value',
validator: 'key-context',
},
]
};
//# sourceMappingURL=VirtualKeyRow.js.map