Add litegraph:group-double-click event (#109)

This commit is contained in:
Chenlei Hu
2024-09-02 17:44:19 -04:00
committed by GitHub
parent a93a1e1a21
commit 48c669626b
2 changed files with 35 additions and 8 deletions

16
public/litegraph.d.ts vendored
View File

@@ -166,12 +166,19 @@ export type LinkReleaseContextExtended = {
links: ConnectingLink[];
};
export type LiteGraphCanvasEventType = "empty-release" | "empty-double-click";
export type LiteGraphCanvasEventType = "empty-release" | "empty-double-click" | "group-double-click";
export type LiteGraphCanvasEvent = CustomEvent<{
subType: string;
originalEvent: Event,
originalEvent: Event;
linkReleaseContext?: LinkReleaseContextExtended;
group?: LGraphGroup;
}>;
export type LiteGraphCanvasGroupEvent = CustomEvent<{
subType: "group-double-click";
originalEvent: MouseEvent;
group: LGraphGroup;
}>;
export const LiteGraph: {
@@ -1121,6 +1128,11 @@ export declare class LGraphGroup {
private _bounding: Vector4;
color: string;
font: string;
size: Vector2;
pos: Vector2;
font_size: number;
get titleHeight(): number;
configure(o: SerializedLGraphGroup): void;
serialize(): SerializedLGraphGroup;

View File

@@ -4844,6 +4844,10 @@ const globalExport = {};
});
}
get titleHeight() {
return this.font_size * 1.4;
}
configure(o) {
this.title = o.title;
this._bounding.set(o.bounding);
@@ -4925,16 +4929,14 @@ const globalExport = {};
};
}, { left: Infinity, top: Infinity, right: -Infinity, bottom: -Infinity });
const groupTitleHeight = Math.round(this.font_size * 1.4);
this.pos = [
bounds.left - padding,
bounds.top - padding - groupTitleHeight
bounds.top - padding - this.titleHeight
];
this.size = [
bounds.right - bounds.left + padding * 2,
bounds.bottom - bounds.top + padding * 2 + groupTitleHeight
bounds.bottom - bounds.top + padding * 2 + this.titleHeight
];
}
}
@@ -7048,9 +7050,22 @@ const globalExport = {};
} else {
this.selected_group.recomputeInsideNodes();
}
}
if (is_double_click && !this.read_only) {
if (is_double_click) {
this.canvas.dispatchEvent(new CustomEvent(
"litegraph:canvas",
{
bubbles: true,
detail: {
subType: "group-double-click",
originalEvent: e,
group: this.selected_group,
}
}
));
}
} else if (is_double_click && !this.read_only) {
// Double click within group should not trigger the searchbox.
if (this.allow_searchbox) {
this.showSearchBox(e);
e.preventDefault();