Skip to content

Commit

Permalink
feat(bindgen): support FLOAT for demo html, typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Aug 21, 2023
1 parent 40f47cb commit cd29c91
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/bindgen/typescript/demo/all-demo-types-supported.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const demoSupportedInputTypes = new Set([
'TEXT',
'INT',
'UINT',
'FLOAT',
'BOOL',
'INPUT_JSON',
'INPUT_IMAGE',
Expand Down
25 changes: 18 additions & 7 deletions src/bindgen/typescript/demo/input-parameters-demo-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function inputParametersDemoHtml (functionName, prefix, indent, parameter, requi
result += `${prefix}${indent}<sl-tooltip ${tooltipContent}><sl-details id="${functionName}-${parameter.name}-details" summary="${label}: ${description}" disabled></sl-details></sl-tooltip>\n`
const multiple = parameter.itemsExpectedMax > 1 ? 'multiple ' : ''
result += `${prefix}${indent}<label for="${parameter.name}-file"><sl-button name="${parameter.name}-file-button" variant="primary" outline onclick="this.parentElement.nextElementSibling.click()">Upload</sp-button></label><input type="file" ${multiple} name="${parameter.name}-file" style="display: none"/>\n`
result += `<br /><br />\n`
result += '<br /><br />\n'
}
break
case 'INPUT_BINARY_FILE':
Expand All @@ -23,31 +23,42 @@ function inputParametersDemoHtml (functionName, prefix, indent, parameter, requi
result += `${prefix}${indent}<sl-tooltip ${tooltipContent}><sl-details id="${functionName}-${parameter.name}-details" summary="${label}: ${description}" disabled></sl-details></sl-tooltip>\n`
const multiple = parameter.itemsExpectedMax > 1 ? 'multiple ' : ''
result += `${prefix}${indent}<label for="${parameter.name}-file"><sl-button name="${parameter.name}-file-button" ${requiredAttr}variant="primary" outline onclick="this.parentElement.nextElementSibling.click()">Upload</sl-button></label><input type="file" ${multiple} name="${parameter.name}-file" style="display: none"/>\n`
result += `<br /><br />\n`
result += '<br /><br />\n'
}
break
case 'TEXT':
result += `${prefix}${indent}<sl-input ${requiredAttr}name="${parameter.name}" type="text" label="${label}" help-text="${description}"></sl-input>\n`
break
case 'INT':
case 'UINT':
case 'FLOAT': {
if (parameter.itemsExpected !== 1 || parameter.itemsExpectedMin !== 1 || parameter.itemsExpectedMax !== 1) {
// TODO
console.error(`INT items != 1 are currently not supported`)
console.error('items != 1 are currently not supported')
process.exit(1)
}
result += `${prefix}${indent}<sl-input ${requiredAttr}name="${parameter.name}" type="number" value="${parameter.default}" label="${label}" help-text="${description}"></sl-input>\n`
result += `<br />\n`
let constraints = ''
if (parameter.type === 'INT') {
constraints = 'step="1"'
} else if (parameter.type === 'UINT') {
constraints = 'min="0" step="1"'
} else if (parameter.type === 'FLOAT') {
constraints = 'step="any"'
}
result += `${prefix}${indent}<sl-input ${requiredAttr}name="${parameter.name}" type="number" value="${parameter.default}" ${constraints} label="${label}" help-text="${description}"></sl-input>\n`
result += '<br />\n'
}
break
case 'BOOL':
result += `${prefix}${indent}<sl-checkbox name="${parameter.name}">${label} - <i>${description}</i></sl-checkbox>\n`
result += `<br /><br />\n`
result += '<br /><br />\n'
break
case 'INPUT_JSON':
case 'INPUT_IMAGE':
case 'INPUT_MESH':
result += `${prefix}${indent}<sl-tooltip ${tooltipContent}><sl-details id="${functionName}-${parameter.name}-details" summary="${label}: ${description}" disabled></sl-details></sl-tooltip>\n`
result += `${prefix}${indent}<label for="${parameter.name}-file"><sl-button name="${parameter.name}-file-button" variant="primary" outline onclick="this.parentElement.nextElementSibling.click()">Upload</sp-button></label><input type="file" name="${parameter.name}-file" style="display: none"/>\n`
result += `<br /><br />\n`
result += '<br /><br />\n'
break
default:
console.error(`Unexpected interface type: ${parameter.type}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,14 @@ function inputParametersDemoTypeScript(functionName, indent, parameter, required
break
case 'INT':
case 'UINT':
case 'FLOAT':
result += `${indent}const ${inputIdentifier} = document.querySelector('#${functionName}Inputs sl-input[name=${parameter.name}]')\n`
result += `${indent}${inputIdentifier}.addEventListener('sl-change', (event) => {\n`
result += `${indent}${indent}model.${modelProperty}.set("${parameterName}", parseInt(${inputIdentifier}.value))\n`
if (parameter.type === 'FLOAT') {
result += `${indent}${indent}model.${modelProperty}.set("${parameterName}", parseFloat(${inputIdentifier}.value))\n`
} else {
result += `${indent}${indent}model.${modelProperty}.set("${parameterName}", parseInt(${inputIdentifier}.value))\n`
}
result += `${indent}})\n\n`
break
case 'INPUT_JSON':
Expand Down

0 comments on commit cd29c91

Please sign in to comment.