fixed canvas resize

This commit is contained in:
2025-05-18 14:44:51 +02:00
parent c6a3056dcd
commit e0797d2cfc
3 changed files with 18 additions and 2 deletions

View File

@@ -24,10 +24,16 @@
align-items: center; align-items: center;
justify-content: center; justify-content: center;
background: black; background: black;
overflow: hidden; /* Prevent canvas from causing wrapper to grow */
} }
canvas { canvas {
display: block; display: block;
max-width: 100%;
max-height: 100%;
width: 100%;
height: 100%;
box-sizing: border-box;
} }
.bottom-panel { .bottom-panel {

View File

@@ -68,14 +68,19 @@ export class VisMain {
}; };
public onResized() { public onResized() {
// Always get the latest wrapper size
const width = this.wrapper.clientWidth; const width = this.wrapper.clientWidth;
const height = this.wrapper.clientHeight; const height = this.wrapper.clientHeight;
const ratio = window.devicePixelRatio; const ratio = window.devicePixelRatio;
// Set canvas style to always fill the wrapper
this.canvas.width = width * ratio; this.canvas.width = width * ratio;
this.canvas.height = height * ratio; this.canvas.height = height * ratio;
this.canvas.style.width = width + "px";
this.canvas.style.height = height + "px"; // Reset transform before scaling to avoid compounding
this.context.setTransform(1, 0, 0, 1, 0, 0);
this.context.scale(ratio, ratio); this.context.scale(ratio, ratio);
this.visLevel.updateSize(); this.visLevel.updateSize();
}; };

View File

@@ -1 +1,6 @@
/* You can add global styles to this file, and also import other style files */ /* You can add global styles to this file, and also import other style files */
html, body {
margin: 0;
padding: 0;
}