Skip to content

Commit beee147

Browse files
committed
fix: Update node.getBounding box to support collapsed nodes and shadows
1 parent 23c300b commit beee147

2 files changed

Lines changed: 32 additions & 10 deletions

File tree

src/litegraph.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,12 @@ export declare class LGraphNode {
825825

826826
/**
827827
* returns the bounding of the object, used for rendering purposes
828-
* @return [x, y, width, height]
828+
* @method getBounding
829+
* @param out [optional] a place to store the output, to free garbage
830+
* @param compute_outer [optional] set to true to include the shadow and connection points in the bounding calculation
831+
* @return the bounding box in format of [topleft_cornerx, topleft_cornery, width, height]
829832
*/
830-
getBounding(): Vector4;
833+
getBounding(out?: Vector4, compute_outer?: boolean): Vector4;
831834
/** checks if a point is inside the shape of a node */
832835
isPointInside(
833836
x: number,

src/litegraph.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3773,16 +3773,35 @@
37733773

37743774
/**
37753775
* returns the bounding of the object, used for rendering purposes
3776-
* bounding is: [topleft_cornerx, topleft_cornery, width, height]
37773776
* @method getBounding
3778-
* @return {Float32Array[4]} the total size
3777+
* @param out {Float32Array[4]?} [optional] a place to store the output, to free garbage
3778+
* @param compute_outer {boolean?} [optional] set to true to include the shadow and connection points in the bounding calculation
3779+
* @return {Float32Array[4]} the bounding box in format of [topleft_cornerx, topleft_cornery, width, height]
37793780
*/
3780-
LGraphNode.prototype.getBounding = function(out) {
3781+
LGraphNode.prototype.getBounding = function(out, compute_outer) {
37813782
out = out || new Float32Array(4);
3782-
out[0] = this.pos[0] - 4;
3783-
out[1] = this.pos[1] - LiteGraph.NODE_TITLE_HEIGHT;
3784-
out[2] = this.size[0] + 4;
3785-
out[3] = this.flags.collapsed ? LiteGraph.NODE_TITLE_HEIGHT : this.size[1] + LiteGraph.NODE_TITLE_HEIGHT;
3783+
const nodePos = this.pos;
3784+
const nodeFlags = this.flags;
3785+
const nodeSize = this.size;
3786+
3787+
// 4 offset for collapsed node connection points
3788+
const left_offset = compute_outer ? 4 : 0;
3789+
// 6 offset for right shadow and collapsed node connection points, 1 offset due to how nodes are rendered
3790+
const right_offset = compute_outer ? 6 + left_offset : 1 ;
3791+
// 4 offset for collapsed nodes top connection points
3792+
const top_offset = compute_outer ? 4 : 0;
3793+
// 5 offset for bottom shadow and collapsed node connection points
3794+
const bottom_offset = compute_outer ? 5 + top_offset : 0;
3795+
3796+
3797+
out[0] = nodePos[0] - left_offset;
3798+
out[1] = nodePos[1] - LiteGraph.NODE_TITLE_HEIGHT - top_offset;
3799+
out[2] = nodeFlags.collapsed ?
3800+
(this._collapsed_width || LiteGraph.NODE_COLLAPSED_WIDTH) + right_offset :
3801+
nodeSize[0] + right_offset;
3802+
out[3] = nodeFlags.collapsed ?
3803+
LiteGraph.NODE_TITLE_HEIGHT + bottom_offset :
3804+
nodeSize[1] + LiteGraph.NODE_TITLE_HEIGHT + bottom_offset;
37863805

37873806
if (this.onBounding) {
37883807
this.onBounding(out);
@@ -7667,7 +7686,7 @@ LGraphNode.prototype.executeAction = function(action)
76677686
continue;
76687687
}
76697688

7670-
if (!overlapBounding(this.visible_area, n.getBounding(temp))) {
7689+
if (!overlapBounding(this.visible_area, n.getBounding(temp, true))) {
76717690
continue;
76727691
} //out of the visible area
76737692

0 commit comments

Comments
 (0)