Restore and save outputAreaBounds in CanvasState

Adds logic to restore outputAreaBounds from saved state if available, or fallback to a default for legacy saves. Also ensures outputAreaBounds is included when saving state, improving consistency across sessions.
This commit is contained in:
Dariusz L
2025-07-27 21:17:52 +02:00
parent 7fc49d72f5
commit 8d6cd783ec
2 changed files with 32 additions and 0 deletions

View File

@@ -68,6 +68,21 @@ export class CanvasState {
y: -(this.canvas.height / 4),
zoom: 0.8
};
// Restore outputAreaBounds if saved, otherwise use default
if (savedState.outputAreaBounds) {
this.canvas.outputAreaBounds = savedState.outputAreaBounds;
log.debug(`Output Area bounds restored: x=${this.canvas.outputAreaBounds.x}, y=${this.canvas.outputAreaBounds.y}, w=${this.canvas.outputAreaBounds.width}, h=${this.canvas.outputAreaBounds.height}`);
}
else {
// Fallback to default positioning for legacy saves
this.canvas.outputAreaBounds = {
x: -(this.canvas.width / 4),
y: -(this.canvas.height / 4),
width: this.canvas.width,
height: this.canvas.height
};
log.debug(`Output Area bounds set to default: x=${this.canvas.outputAreaBounds.x}, y=${this.canvas.outputAreaBounds.y}, w=${this.canvas.outputAreaBounds.width}, h=${this.canvas.outputAreaBounds.height}`);
}
this.canvas.canvasLayers.updateOutputAreaSize(this.canvas.width, this.canvas.height, false);
log.debug(`Output Area resized to ${this.canvas.width}x${this.canvas.height} and viewport set.`);
const loadedLayers = await this._loadLayers(savedState.layers);
@@ -229,6 +244,7 @@ export class CanvasState {
viewport: this.canvas.viewport,
width: this.canvas.width,
height: this.canvas.height,
outputAreaBounds: this.canvas.outputAreaBounds,
};
if (state.layers.length === 0) {
log.warn("No valid layers to save, skipping.");

View File

@@ -98,6 +98,21 @@ export class CanvasState {
zoom: 0.8
};
// Restore outputAreaBounds if saved, otherwise use default
if (savedState.outputAreaBounds) {
this.canvas.outputAreaBounds = savedState.outputAreaBounds;
log.debug(`Output Area bounds restored: x=${this.canvas.outputAreaBounds.x}, y=${this.canvas.outputAreaBounds.y}, w=${this.canvas.outputAreaBounds.width}, h=${this.canvas.outputAreaBounds.height}`);
} else {
// Fallback to default positioning for legacy saves
this.canvas.outputAreaBounds = {
x: -(this.canvas.width / 4),
y: -(this.canvas.height / 4),
width: this.canvas.width,
height: this.canvas.height
};
log.debug(`Output Area bounds set to default: x=${this.canvas.outputAreaBounds.x}, y=${this.canvas.outputAreaBounds.y}, w=${this.canvas.outputAreaBounds.width}, h=${this.canvas.outputAreaBounds.height}`);
}
this.canvas.canvasLayers.updateOutputAreaSize(this.canvas.width, this.canvas.height, false);
log.debug(`Output Area resized to ${this.canvas.width}x${this.canvas.height} and viewport set.`);
const loadedLayers = await this._loadLayers(savedState.layers);
@@ -264,6 +279,7 @@ export class CanvasState {
viewport: this.canvas.viewport,
width: this.canvas.width,
height: this.canvas.height,
outputAreaBounds: this.canvas.outputAreaBounds,
};
if (state.layers.length === 0) {