MCPcopy Create free account
hub / github.com/Comfy-Org/litegraph.js / getWidgetOnPos

Method getWidgetOnPos

src/LGraphNode.ts:2039–2071  ·  view source on GitHub ↗

* Gets the widget on this node at the given co-ordinates. * @param canvasX X co-ordinate in graph space * @param canvasY Y co-ordinate in graph space * @returns The widget found, otherwise `null`

(
    canvasX: number,
    canvasY: number,
    includeDisabled = false,
  )

Source from the content-addressed store, hash-verified

2037 * @returns The widget found, otherwise `null`
2038 */
2039 getWidgetOnPos(
2040 canvasX: number,
2041 canvasY: number,
2042 includeDisabled = false,
2043 ): IBaseWidget | undefined {
2044 const { widgets, pos, size } = this
2045 if (!widgets?.length) return
2046
2047 const x = canvasX - pos[0]
2048 const y = canvasY - pos[1]
2049 const nodeWidth = size[0]
2050
2051 for (const widget of widgets) {
2052 if (
2053 (widget.computedDisabled && !includeDisabled) ||
2054 !this.isWidgetVisible(widget)
2055 ) {
2056 continue
2057 }
2058
2059 const h = widget.computedHeight ??
2060 widget.computeSize?.(nodeWidth)[1] ??
2061 LiteGraph.NODE_WIDGET_HEIGHT
2062
2063 const w = widget.width || nodeWidth
2064 if (
2065 widget.last_y !== undefined &&
2066 isInRectangle(x, y, 6, widget.last_y, w - 12, h)
2067 ) {
2068 return widget
2069 }
2070 }
2071 }
2072
2073 /**
2074 * Returns the input slot with a given name (used for dynamic slots), -1 if not found

Callers 3

getWidgetAtCursorMethod · 0.80
#processNodeClickMethod · 0.80
processMouseMoveMethod · 0.80

Calls 3

isWidgetVisibleMethod · 0.95
isInRectangleFunction · 0.90
computeSizeMethod · 0.65

Tested by

no test coverage detected