mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-24 14:02:11 -03:00
Add layer fusion (flatten/merge) feature
Introduces a new 'Fuse' button to the canvas UI, allowing users to flatten and merge multiple selected layers into a single layer. The implementation handles bounding box calculation, z-index ordering, and updates the canvas state and selection accordingly. The fuse button is enabled only when at least two layers are selected.
This commit is contained in:
@@ -789,6 +789,11 @@ async function createCanvasWidget(node, widget, app) {
|
||||
title: "Move selected layer(s) down",
|
||||
onclick: () => canvas.canvasLayers.moveLayerDown()
|
||||
}),
|
||||
$el("button.painter-button.requires-selection", {
|
||||
textContent: "Fuse",
|
||||
title: "Flatten and merge selected layers into a single layer",
|
||||
onclick: () => canvas.canvasLayers.fuseLayers()
|
||||
}),
|
||||
]),
|
||||
|
||||
$el("div.painter-separator"),
|
||||
@@ -1008,7 +1013,12 @@ async function createCanvasWidget(node, widget, app) {
|
||||
const selectionCount = canvas.selectedLayers.length;
|
||||
const hasSelection = selectionCount > 0;
|
||||
controlPanel.querySelectorAll('.requires-selection').forEach(btn => {
|
||||
btn.disabled = !hasSelection;
|
||||
// Special handling for Fuse button - requires at least 2 layers
|
||||
if (btn.textContent === 'Fuse') {
|
||||
btn.disabled = selectionCount < 2;
|
||||
} else {
|
||||
btn.disabled = !hasSelection;
|
||||
}
|
||||
});
|
||||
const mattingBtn = controlPanel.querySelector('.matting-button');
|
||||
if (mattingBtn && !mattingBtn.classList.contains('loading')) {
|
||||
|
||||
Reference in New Issue
Block a user