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

Method drawTitleText

src/LGraphNode.ts:3378–3451  ·  view source on GitHub ↗

* Renders the node's title text.

(ctx: CanvasRenderingContext2D, {
    scale,
    default_title_color,
    low_quality = false,
    title_height = LiteGraph.NODE_TITLE_HEIGHT,
  }: DrawTitleTextOptions)

Source from the content-addressed store, hash-verified

3376 * Renders the node's title text.
3377 */
3378 drawTitleText(ctx: CanvasRenderingContext2D, {
3379 scale,
3380 default_title_color,
3381 low_quality = false,
3382 title_height = LiteGraph.NODE_TITLE_HEIGHT,
3383 }: DrawTitleTextOptions): void {
3384 const size = this.renderingSize
3385 const selected = this.selected
3386
3387 if (this.onDrawTitleText) {
3388 this.onDrawTitleText(
3389 ctx,
3390 title_height,
3391 size,
3392 scale,
3393 this.titleFontStyle,
3394 selected,
3395 )
3396 return
3397 }
3398
3399 // Don't render title text if low quality
3400 if (low_quality) {
3401 return
3402 }
3403
3404 ctx.font = this.titleFontStyle
3405 const rawTitle = this.getTitle() ?? `❌ ${this.type}`
3406 const title = String(rawTitle) + (this.pinned ? "📌" : "")
3407 if (title) {
3408 if (selected) {
3409 ctx.fillStyle = LiteGraph.NODE_SELECTED_TITLE_COLOR
3410 } else {
3411 ctx.fillStyle = this.constructor.title_text_color || default_title_color
3412 }
3413
3414 // Calculate available width for title
3415 let availableWidth = size[0] - title_height * 2 // Basic margins
3416
3417 // Subtract space for title buttons
3418 if (this.title_buttons?.length > 0) {
3419 let buttonsWidth = 0
3420 const savedFont = ctx.font // Save current font
3421 for (const button of this.title_buttons) {
3422 if (button.visible) {
3423 buttonsWidth += button.getWidth(ctx) + 2 // button width + gap
3424 }
3425 }
3426 ctx.font = savedFont // Restore font after button measurements
3427 if (buttonsWidth > 0) {
3428 buttonsWidth += 10 // Extra margin before buttons
3429 availableWidth -= buttonsWidth
3430 }
3431 }
3432
3433 // Truncate title if needed
3434 let displayTitle = title
3435

Callers 1

drawNodeShapeMethod · 0.80

Calls 3

getTitleMethod · 0.95
truncateTextFunction · 0.90
getWidthMethod · 0.45

Tested by

no test coverage detected