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

Method measure

src/LGraphNode.ts:1883–1904  ·  view source on GitHub ↗

* Internal method to measure the node for rendering. Prefer boundingRect where possible. * * Populates out with the results in graph space. * Populates _collapsed_width with the collapsed width if the node is collapsed. * Adjusts for title and collapsed status, b

(out: Rect, ctx: CanvasRenderingContext2D)

Source from the content-addressed store, hash-verified

1881 * @param ctx The canvas context to use for measuring text.
1882 */
1883 measure(out: Rect, ctx: CanvasRenderingContext2D): void {
1884 const titleMode = this.title_mode
1885 const renderTitle =
1886 titleMode != TitleMode.TRANSPARENT_TITLE &&
1887 titleMode != TitleMode.NO_TITLE
1888 const titleHeight = renderTitle ? LiteGraph.NODE_TITLE_HEIGHT : 0
1889
1890 out[0] = this.pos[0]
1891 out[1] = this.pos[1] + -titleHeight
1892 if (!this.flags?.collapsed) {
1893 out[2] = this.size[0]
1894 out[3] = this.size[1] + titleHeight
1895 } else {
1896 ctx.font = this.innerFontStyle
1897 this._collapsed_width = Math.min(
1898 this.size[0],
1899 ctx.measureText(this.getTitle() ?? "").width + LiteGraph.NODE_TITLE_HEIGHT * 2,
1900 )
1901 out[2] = (this._collapsed_width || LiteGraph.NODE_COLLAPSED_WIDTH)
1902 out[3] = LiteGraph.NODE_TITLE_HEIGHT
1903 }
1904 }
1905
1906 /**
1907 * returns the bounding of the object, used for rendering purposes

Callers 2

updateAreaMethod · 0.95
arrangeFunction · 0.80

Calls 1

getTitleMethod · 0.95

Tested by

no test coverage detected