[Refactor] Move node title background draw logic to LGraphNode (#452)

This commit is contained in:
Chenlei Hu
2025-02-03 20:20:51 -08:00
committed by GitHub
parent 9a1c322490
commit 047bf68dc9
2 changed files with 55 additions and 30 deletions

View File

@@ -5233,36 +5233,10 @@ export class LGraphCanvas {
// Title bar background (remember, it is rendered ABOVE the node)
if (render_title || title_mode == TitleMode.TRANSPARENT_TITLE) {
if (node.onDrawTitleBar) {
node.onDrawTitleBar(ctx, title_height, size, this.ds.scale, fgcolor)
} else if (
title_mode !== TitleMode.TRANSPARENT_TITLE
) {
const title_color = node.constructor.title_color || fgcolor
if (collapsed) {
ctx.shadowColor = LiteGraph.DEFAULT_SHADOW_COLOR
}
ctx.fillStyle = title_color
ctx.beginPath()
if (shape == RenderShape.BOX || low_quality) {
ctx.rect(0, -title_height, size[0], title_height)
} else if (shape == RenderShape.ROUND || shape == RenderShape.CARD) {
ctx.roundRect(
0,
-title_height,
size[0],
title_height,
collapsed
? [LiteGraph.ROUND_RADIUS]
: [LiteGraph.ROUND_RADIUS, LiteGraph.ROUND_RADIUS, 0, 0],
)
}
ctx.fill()
ctx.shadowColor = "transparent"
}
node.drawTitleBarBackground(ctx, {
scale: this.ds.scale,
low_quality,
})
// title box
const box_size = 10