Support multiple batch preview menus on canvas

Refactored batch preview management to allow multiple BatchPreviewManager instances per canvas. Updated positioning logic to use an initial spawn position, adjusted UI updates, and ensured batch preview menus move correctly with canvas panning. Removed single-instance references and updated related event handling.
This commit is contained in:
Dariusz L
2025-07-03 03:55:04 +02:00
parent f8eb91c4ad
commit e5060fd8c3
4 changed files with 56 additions and 19 deletions

View File

@@ -167,7 +167,8 @@ export class Canvas {
this.canvasRenderer = new CanvasRenderer(this);
this.canvasIO = new CanvasIO(this);
this.imageReferenceManager = new ImageReferenceManager(this);
this.batchPreviewManager = new BatchPreviewManager(this);
this.batchPreviewManagers = [];
this.pendingBatchSpawnPosition = null;
log.debug('Canvas modules initialized successfully');
}
@@ -485,7 +486,12 @@ export class Canvas {
const handleExecutionStart = () => {
lastExecutionStartTime = Date.now();
log.debug(`Execution started, timestamp set to: ${lastExecutionStartTime}`);
// Store the spawn position for the next batch menu, relative to the output area
this.pendingBatchSpawnPosition = {
x: this.width / 2, // Horizontally centered on the output area
y: this.height // At the bottom of the output area
};
log.debug(`Execution started, pending spawn position set relative to output area at:`, this.pendingBatchSpawnPosition);
};
const handleExecutionSuccess = async () => {
@@ -494,7 +500,20 @@ export class Canvas {
const newLayers = await this.canvasIO.importLatestImages(lastExecutionStartTime);
if (newLayers && newLayers.length > 1) {
this.batchPreviewManager.show(newLayers);
if (!this.pendingBatchSpawnPosition) {
// Fallback in case execution_start didn't fire
this.pendingBatchSpawnPosition = {
x: this.width / 2,
y: this.height
};
log.warn("execution_start did not fire, using fallback spawn position.");
}
const newManager = new BatchPreviewManager(this, this.pendingBatchSpawnPosition);
this.batchPreviewManagers.push(newManager);
newManager.show(newLayers);
this.pendingBatchSpawnPosition = null; // Consume the position
}
}
};