Shuffle around some ops in PreviewCanvas

This commit is contained in:
Ingvar Stepanyan
2021-07-20 15:07:22 +00:00
parent 51864cc154
commit 379c6ead81

35
ui.js
View File

@@ -380,9 +380,6 @@ class PreviewCanvas extends Component {
}
async componentDidMount() {
// I have no idea why, but if we connect too soon, it just hangs...
await new Promise(resolve => setTimeout(resolve, 1000));
let canvas = /** @type {HTMLCanvasElement} */ (this.ref.current);
let canvasHolder = canvas.parentElement;
@@ -390,6 +387,23 @@ class PreviewCanvas extends Component {
let ratio = 0;
function updateCanvasSize() {
let width = canvasHolder.offsetWidth - 10;
let height = canvasHolder.offsetHeight;
if (height * ratio > width) {
height = width / ratio;
} else {
width = height * ratio;
}
Object.assign(canvas, { width, height });
}
new ResizeObserver(updateCanvasSize).observe(canvasHolder);
// I have no idea why, but if we connect too soon, it just hangs...
await new Promise(resolve => setTimeout(resolve, 1000));
while (true) {
try {
let blob = await scheduleOp(context => context.capturePreviewAsBlob());
@@ -407,22 +421,7 @@ class PreviewCanvas extends Component {
);
if (!ratio) {
ratio = img.width / img.height;
function updateCanvasSize() {
let width = canvasHolder.offsetWidth - 10;
let height = canvasHolder.offsetHeight;
if (height * ratio > width) {
height = width / ratio;
} else {
width = height * ratio;
}
Object.assign(canvas, { width, height });
}
updateCanvasSize();
new ResizeObserver(updateCanvasSize).observe(canvasHolder);
}
canvasCtx.transferFromImageBitmap(img);
} catch (e) {