Skip to content

Commit aac9cc1

Browse files
committed
Reimplement initialMinSize
The functionality is dumb and wrong, but required to keep expected sizing behaviour for nodes like Clip Text Encode
1 parent f1d1806 commit aac9cc1

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

src/services/litegraphService.ts

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ import { getOrderedInputSpecs } from '@/workbench/utils/nodeDefOrderingUtil'
5959

6060
import { useExtensionService } from './extensionService'
6161

62+
interface HasInitialMinSize {
63+
_initialMinSize: { width: number; height: number }
64+
}
65+
6266
export const CONFIG = Symbol()
6367
export const GET_CONFIG = Symbol()
6468

@@ -146,13 +150,16 @@ export const useLitegraphService = () => {
146150
const widgetConstructor = widgetStore.widgets.get(widgetInputSpec.type)
147151
if (!widgetConstructor || inputSpec.forceInput) return
148152

149-
const { widget } =
150-
widgetConstructor(
151-
node,
152-
inputName,
153-
transformInputSpecV2ToV1(widgetInputSpec),
154-
app
155-
) ?? {}
153+
const {
154+
widget,
155+
minWidth = 1,
156+
minHeight = 1
157+
} = widgetConstructor(
158+
node,
159+
inputName,
160+
transformInputSpecV2ToV1(widgetInputSpec),
161+
app
162+
) ?? {}
156163

157164
if (widget) {
158165
widget.label = st(nameKey, widget.label ?? inputName)
@@ -171,6 +178,15 @@ export const useLitegraphService = () => {
171178
widget: { name: inputName, [GET_CONFIG]: () => inputSpecV1 }
172179
})
173180
}
181+
const castedNode = node as LGraphNode & HasInitialMinSize
182+
castedNode._initialMinSize.width = Math.max(
183+
castedNode._initialMinSize.width,
184+
minWidth
185+
)
186+
castedNode._initialMinSize.height = Math.max(
187+
castedNode._initialMinSize.height,
188+
minHeight
189+
)
174190
}
175191

176192
/**
@@ -217,7 +233,9 @@ export const useLitegraphService = () => {
217233
const pad =
218234
node.widgets?.length &&
219235
!useSettingStore().get('LiteGraph.Node.DefaultPadding')
220-
s[0] = s[0] + (pad ? 60 : 0)
236+
const castedNode = node as LGraphNode & HasInitialMinSize
237+
s[0] = Math.max(castedNode._initialMinSize.width, s[0] + (pad ? 60 : 0))
238+
s[1] = Math.max(castedNode._initialMinSize.height, s[1])
221239
node.setSize(s)
222240
}
223241

@@ -226,12 +244,17 @@ export const useLitegraphService = () => {
226244
subgraph: Subgraph,
227245
instanceData: ExportedSubgraphInstance
228246
) {
229-
const node = class ComfyNode extends SubgraphNode {
247+
const node = class ComfyNode
248+
extends SubgraphNode
249+
implements HasInitialMinSize
250+
{
230251
static comfyClass: string
231252
static override title: string
232253
static override category: string
233254
static nodeData: ComfyNodeDefV1 & ComfyNodeDefV2
234255

256+
_initialMinSize = { width: 1, height: 1 }
257+
235258
constructor() {
236259
super(app.graph, subgraph, instanceData)
237260

@@ -354,12 +377,17 @@ export const useLitegraphService = () => {
354377
}
355378

356379
async function registerNodeDef(nodeId: string, nodeDefV1: ComfyNodeDefV1) {
357-
const node = class ComfyNode extends LGraphNode {
380+
const node = class ComfyNode
381+
extends LGraphNode
382+
implements HasInitialMinSize
383+
{
358384
static comfyClass: string
359385
static override title: string
360386
static override category: string
361387
static nodeData: ComfyNodeDefV1 & ComfyNodeDefV2
362388

389+
_initialMinSize = { width: 1, height: 1 }
390+
363391
constructor(title: string) {
364392
super(title)
365393
setupStrokeStyles(this)

0 commit comments

Comments
 (0)