Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add onNodeTitleDblClick hook #88

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions public/litegraph.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,30 @@ export declare class LGraphNode {
): void;
onKey?(event: KeyboardEvent, pos: Vector2, graphCanvas: LGraphCanvas): void;

onDblClick?(
event: MouseEvent,
pos: Vector2,
graphCanvas: LGraphCanvas
): void;

onNodeTitleDblClick?(
event: MouseEvent,
pos: Vector2,
graphCanvas: LGraphCanvas
): void;

onInputDblClick?(
event: MouseEvent,
pos: Vector2,
graphCanvas: LGraphCanvas
): void;

onOutputDblClick?(
event: MouseEvent,
pos: Vector2,
graphCanvas: LGraphCanvas
): void;

/** Called by `LGraphCanvas.selectNodes` */
onSelected?(): void;
/** Called by `LGraphCanvas.deselectNode` */
Expand Down
9 changes: 7 additions & 2 deletions src/litegraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -2317,6 +2317,7 @@ const globalExport = {};
+ onGetOutputs: returns an array of possible outputs
+ onBounding: in case this node has a bigger bounding than the node itself (the callback receives the bounding as [x,y,w,h])
+ onDblClick: double clicked in the node
+ onNodeTitleDblClick: double clicked in the node title
+ onInputDblClick: input slot double clicked (can be used to automatically create a node connected)
+ onOutputDblClick: output slot double clicked (can be used to automatically create a node connected)
+ onConfigure: called after the node has been configured
Expand Down Expand Up @@ -5956,7 +5957,7 @@ LGraphNode.prototype.executeAction = function(action)

if (is_double_click) {
if (node.onOutputDblClick) {
node.onOutputDblClick(i, e);
node.onOutputDblClick(i, e, this);
}
} else {
if (node.onOutputClick) {
Expand Down Expand Up @@ -5987,7 +5988,7 @@ LGraphNode.prototype.executeAction = function(action)
) {
if (is_double_click) {
if (node.onInputDblClick) {
node.onInputDblClick(i, e);
node.onInputDblClick(i, e, this);
}
} else {
if (node.onInputClick) {
Expand Down Expand Up @@ -6072,6 +6073,10 @@ LGraphNode.prototype.executeAction = function(action)

//double clicking
if (this.allow_interaction && is_double_click && this.selected_nodes[node.id]) {
//check if it's a double click on the title bar
if (pos[1] < LiteGraph.NODE_TITLE_HEIGHT) {
node?.onNodeTitleDblClick(e, pos, this);
}
//double click node
if (node.onDblClick) {
node.onDblClick( e, pos, this );
Expand Down
Loading