Skip to content

Commit bfe083d

Browse files
Move subgraph badge into node title (#6115)
<img width="1350" height="691" alt="image" src="https://github.com/user-attachments/assets/4a1a909f-463e-4c77-8855-6fe0a177b659" /> Design docs show icon as being reversed in litegraph mode. If needed, fixing this is basically just removing a negative sign. LiteGraph implementation was not as clean as I hoped. I can spend some more time divining some non-magic constants, and mayybe resolve the svg data from css styles if desired. Resolves #4647 Resolves #6107 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6115-Move-subgraph-badge-into-node-title-2906d73d365081e4ba82d321fc27afed) by [Unito](https://www.unito.io) --------- Co-authored-by: GitHub Action <[email protected]>
1 parent 917f8ae commit bfe083d

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

src/lib/litegraph/src/LGraphNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ interface DrawTitleTextOptions extends DrawTitleOptions {
151151
default_title_color: string
152152
}
153153

154-
interface DrawTitleBoxOptions extends DrawTitleOptions {
154+
export interface DrawTitleBoxOptions extends DrawTitleOptions {
155155
box_size?: number
156156
}
157157

src/lib/litegraph/src/subgraph/SubgraphNode.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import type { BaseLGraph, LGraph } from '@/lib/litegraph/src/LGraph'
22
import type { LGraphButton } from '@/lib/litegraph/src/LGraphButton'
33
import type { LGraphCanvas } from '@/lib/litegraph/src/LGraphCanvas'
44
import { LGraphNode } from '@/lib/litegraph/src/LGraphNode'
5+
import type { DrawTitleBoxOptions } from '@/lib/litegraph/src/LGraphNode'
56
import { LLink } from '@/lib/litegraph/src/LLink'
67
import type { ResolvedConnection } from '@/lib/litegraph/src/LLink'
78
import { RecursionError } from '@/lib/litegraph/src/infrastructure/RecursionError'
89
import type {
910
ISubgraphInput,
1011
IWidgetLocator
1112
} from '@/lib/litegraph/src/interfaces'
13+
import { LiteGraph } from '@/lib/litegraph/src/litegraph'
1214
import type {
1315
INodeInputSlot,
1416
ISlotType,
@@ -32,6 +34,10 @@ import { ExecutableNodeDTO } from './ExecutableNodeDTO'
3234
import type { ExecutableLGraphNode, ExecutionId } from './ExecutableNodeDTO'
3335
import type { SubgraphInput } from './SubgraphInput'
3436

37+
const workflowSvg = new Image()
38+
workflowSvg.src =
39+
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' width='16' height='16'%3E%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 16 16'%3E%3Cpath stroke='white' stroke-linecap='round' stroke-width='1.3' d='M9.18613 3.09999H6.81377M9.18613 12.9H7.55288c-3.08678 0-5.35171-2.99581-4.60305-6.08843l.3054-1.26158M14.7486 2.1721l-.5931 2.45c-.132.54533-.6065.92789-1.1508.92789h-2.2993c-.77173 0-1.33797-.74895-1.1508-1.5221l.5931-2.45c.132-.54533.6065-.9279 1.1508-.9279h2.2993c.7717 0 1.3379.74896 1.1508 1.52211Zm-8.3033 0-.59309 2.45c-.13201.54533-.60646.92789-1.15076.92789H2.4021c-.7717 0-1.33793-.74895-1.15077-1.5221l.59309-2.45c.13201-.54533.60647-.9279 1.15077-.9279h2.29935c.77169 0 1.33792.74896 1.15076 1.52211Zm8.3033 9.8-.5931 2.45c-.132.5453-.6065.9279-1.1508.9279h-2.2993c-.77173 0-1.33797-.749-1.1508-1.5221l.5931-2.45c.132-.5453.6065-.9279 1.1508-.9279h2.2993c.7717 0 1.3379.7489 1.1508 1.5221Z'/%3E%3C/svg%3E %3C/svg%3E"
40+
3541
/**
3642
* An instance of a {@link Subgraph}, displayed as a node on the containing (parent) graph.
3743
*/
@@ -555,6 +561,31 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph {
555561
}
556562
}
557563
}
564+
override drawTitleBox(
565+
ctx: CanvasRenderingContext2D,
566+
{
567+
scale,
568+
low_quality = false,
569+
title_height = LiteGraph.NODE_TITLE_HEIGHT,
570+
box_size = 10
571+
}: DrawTitleBoxOptions
572+
): void {
573+
if (this.onDrawTitleBox) {
574+
this.onDrawTitleBox(ctx, title_height, this.renderingSize, scale)
575+
return
576+
}
577+
ctx.save()
578+
ctx.fillStyle = '#3b82f6'
579+
ctx.beginPath()
580+
ctx.roundRect(6, -24.5, 22, 20, 5)
581+
ctx.fill()
582+
if (!low_quality) {
583+
ctx.translate(25, 23)
584+
ctx.scale(-1.5, 1.5)
585+
ctx.drawImage(workflowSvg, 0, -title_height, box_size, box_size)
586+
}
587+
ctx.restore()
588+
}
558589

559590
/**
560591
* Synchronizes widget values from this SubgraphNode instance to the

src/renderer/extensions/vueNodes/components/NodeHeader.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
</IconButton>
3838
</div>
3939

40+
<div v-if="isSubgraphNode" class="icon-[comfy--workflow] size-4" />
4041
<!-- Node Title -->
4142
<div
4243
v-tooltip.top="tooltipConfig"

src/services/litegraphService.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { addWidgetPromotionOptions } from '@/core/graph/subgraph/proxyWidgetUtil
88
import { showSubgraphNodeDialog } from '@/core/graph/subgraph/useSubgraphNodeDialog'
99
import { st, t } from '@/i18n'
1010
import {
11-
LGraphBadge,
1211
LGraphCanvas,
1312
LGraphEventMode,
1413
LGraphNode,
@@ -135,19 +134,6 @@ export const useLitegraphService = () => {
135134
this.#setInitialSize()
136135
this.serialize_widgets = true
137136
void extensionService.invokeExtensionsAsync('nodeCreated', this)
138-
this.badges.push(
139-
new LGraphBadge({
140-
text: '',
141-
iconOptions: {
142-
unicode: '\ue96e',
143-
fontFamily: 'PrimeIcons',
144-
color: '#ffffff',
145-
fontSize: 12
146-
},
147-
fgColor: '#ffffff',
148-
bgColor: '#3b82f6'
149-
})
150-
)
151137
}
152138

153139
/**

0 commit comments

Comments
 (0)