working web ui

This commit is contained in:
Robin Appelman 2025-10-06 21:54:21 +02:00
commit 88e6fa3244
2 changed files with 21 additions and 1 deletions

View file

@ -14,7 +14,7 @@
</tbody> </tbody>
<tfoot> <tfoot>
<td> <td>
<input type="button" value="Add" id="add"/> <input type="button" value="Add Text" id="add"/>
</td> </td>
</tfoot> </tfoot>
</table> </table>
@ -29,6 +29,10 @@
</p> </p>
<canvas id="preview" height="32" width="300"></canvas> <canvas id="preview" height="32" width="300"></canvas>
<p>
<input type="button" value="Print" id="print"/>
</p>
<script src="label.js"></script> <script src="label.js"></script>
</body> </body>
</html> </html>

View file

@ -4,6 +4,8 @@ const preview = document.getElementById('preview');
const renderCtx = preview.getContext("2d"); const renderCtx = preview.getContext("2d");
const elementsTableBody = elementsTable.getElementsByTagName('tbody')[0]; const elementsTableBody = elementsTable.getElementsByTagName('tbody')[0];
const addButton = document.getElementById('add'); const addButton = document.getElementById('add');
/** @type HTMLInputElement printButton */
const printButton = document.getElementById('print');
const widthInput = document.getElementById('canvas-width'); const widthInput = document.getElementById('canvas-width');
const widthUnit = document.getElementById('canvas-width-unit'); const widthUnit = document.getElementById('canvas-width-unit');
@ -128,7 +130,21 @@ const resize = () => {
render() render()
}; };
const print = () => {
printButton.disabled = true;
preview.toBlob(blob => {
blob.arrayBuffer().then(png => fetch(apiRoot + '/print', {
method: 'PUT',
body: png,
}))
.then(() => {
printButton.disabled = false;
});
}, 'image/png');
};
addButton.addEventListener('click', addElement); addButton.addEventListener('click', addElement);
printButton.addEventListener('click', print);
widthInput.addEventListener('input', resize); widthInput.addEventListener('input', resize);
widthUnit.addEventListener('change', () => { widthUnit.addEventListener('change', () => {