mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-26 06:45:44 -03:00
Add onInteractionEnd callback to Canvas
Introduces an optional onInteractionEnd callback to the Canvas class, which is triggered at the end of user interactions. CanvasView now uses this callback to update output after interactions, improving responsiveness to user actions.
This commit is contained in:
@@ -11,7 +11,7 @@ import {createModuleLogger} from "./utils/LoggerUtils.js";
|
|||||||
const log = createModuleLogger('Canvas');
|
const log = createModuleLogger('Canvas');
|
||||||
|
|
||||||
export class Canvas {
|
export class Canvas {
|
||||||
constructor(node, widget) {
|
constructor(node, widget, callbacks = {}) {
|
||||||
this.node = node;
|
this.node = node;
|
||||||
this.widget = widget;
|
this.widget = widget;
|
||||||
this.canvas = document.createElement('canvas');
|
this.canvas = document.createElement('canvas');
|
||||||
@@ -22,6 +22,7 @@ export class Canvas {
|
|||||||
this.selectedLayer = null;
|
this.selectedLayer = null;
|
||||||
this.selectedLayers = [];
|
this.selectedLayers = [];
|
||||||
this.onSelectionChange = null;
|
this.onSelectionChange = null;
|
||||||
|
this.onInteractionEnd = callbacks.onInteractionEnd || null;
|
||||||
this.lastMousePosition = {x: 0, y: 0};
|
this.lastMousePosition = {x: 0, y: 0};
|
||||||
|
|
||||||
this.viewport = {
|
this.viewport = {
|
||||||
|
|||||||
@@ -172,6 +172,9 @@ export class CanvasInteractions {
|
|||||||
if (interactionEnded) {
|
if (interactionEnded) {
|
||||||
this.canvas.saveState();
|
this.canvas.saveState();
|
||||||
this.canvas.saveStateToDB(true);
|
this.canvas.saveStateToDB(true);
|
||||||
|
if (this.canvas.onInteractionEnd) {
|
||||||
|
this.canvas.onInteractionEnd();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ import {createModuleLogger} from "./utils/LoggerUtils.js";
|
|||||||
const log = createModuleLogger('Canvas_view');
|
const log = createModuleLogger('Canvas_view');
|
||||||
|
|
||||||
async function createCanvasWidget(node, widget, app) {
|
async function createCanvasWidget(node, widget, app) {
|
||||||
const canvas = new Canvas(node, widget);
|
const canvas = new Canvas(node, widget, {
|
||||||
|
onInteractionEnd: () => updateOutput()
|
||||||
|
});
|
||||||
const imageCache = new ImageCache();
|
const imageCache = new ImageCache();
|
||||||
|
|
||||||
const style = document.createElement('style');
|
const style = document.createElement('style');
|
||||||
|
|||||||
Reference in New Issue
Block a user