mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-05 13:41:59 +00:00
Continuation of #6034 with - Updated synchronization for seed - Properly truncates the displayed widget value for the button - Synchronizes control after generate state with litegraph and allows for serialization Several issues from original PR have not (yet) been addressed, but are likely better moved to future PR - fix step value being 10 (legacy system) - ensure it works with COMBO (Fixed in #7095) - ensure it works with FLOAT (Fixed in #7095) - either implement or remove the config button functionality - think it should open settings? <img width="280" height="694" alt="image" src="https://github.com/user-attachments/assets/f36f1cb0-237d-4bfc-bff1-e4976775cf98" /> ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6985-Support-control-after-generate-in-vue-2b86d73d365081d8b01ce489d887ff00) by [Unito](https://www.unito.io) --------- Co-authored-by: bymyself <cbyrne@comfy.org> Co-authored-by: github-actions <github-actions@github.com>
90 lines
2.7 KiB
TypeScript
90 lines
2.7 KiB
TypeScript
import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
|
|
import type { INumericWidget } from '@/lib/litegraph/src/types/widgets'
|
|
import { useSettingStore } from '@/platform/settings/settingStore'
|
|
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
|
|
import { isIntInputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
|
|
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
|
|
import { addValueControlWidget } from '@/scripts/widgets'
|
|
import { transformInputSpecV2ToV1 } from '@/schemas/nodeDef/migration'
|
|
|
|
function onValueChange(this: INumericWidget, v: number) {
|
|
// For integers, always round to the nearest step
|
|
// step === 0 is invalid, assign 1 if options.step is 0
|
|
const step = this.options.step2 || 1
|
|
|
|
if (step === 1) {
|
|
// Simple case: round to nearest integer
|
|
this.value = Math.round(v)
|
|
} else {
|
|
// Round to nearest multiple of step
|
|
// First, determine if min value creates an offset
|
|
const min = this.options.min ?? 0
|
|
const offset = min % step
|
|
|
|
// Round to nearest step, accounting for offset
|
|
this.value = Math.round((v - offset) / step) * step + offset
|
|
}
|
|
}
|
|
|
|
export const _for_testing = {
|
|
onValueChange
|
|
}
|
|
|
|
export const useIntWidget = () => {
|
|
const widgetConstructor: ComfyWidgetConstructorV2 = (
|
|
node: LGraphNode,
|
|
inputSpec: InputSpec
|
|
) => {
|
|
if (!isIntInputSpec(inputSpec)) {
|
|
throw new Error(`Invalid input data: ${inputSpec}`)
|
|
}
|
|
|
|
const settingStore = useSettingStore()
|
|
const sliderEnabled = !settingStore.get('Comfy.DisableSliders')
|
|
const display_type = inputSpec.display
|
|
const widgetType =
|
|
sliderEnabled && display_type == 'slider'
|
|
? 'slider'
|
|
: display_type == 'knob'
|
|
? 'knob'
|
|
: 'number'
|
|
|
|
const step = inputSpec.step ?? 1
|
|
/** Assertion {@link inputSpec.default} */
|
|
const defaultValue = (inputSpec.default as number | undefined) ?? 0
|
|
const widget = node.addWidget(
|
|
widgetType,
|
|
inputSpec.name,
|
|
defaultValue,
|
|
onValueChange,
|
|
{
|
|
min: inputSpec.min ?? 0,
|
|
max: inputSpec.max ?? 2048,
|
|
/** @deprecated Use step2 instead. The 10x value is a legacy implementation. */
|
|
step: step * 10,
|
|
step2: step,
|
|
precision: 0
|
|
}
|
|
)
|
|
|
|
const controlAfterGenerate =
|
|
inputSpec.control_after_generate ??
|
|
['seed', 'noise_seed'].includes(inputSpec.name)
|
|
|
|
if (controlAfterGenerate) {
|
|
const controlWidget = addValueControlWidget(
|
|
node,
|
|
widget,
|
|
'randomize',
|
|
undefined,
|
|
undefined,
|
|
transformInputSpecV2ToV1(inputSpec)
|
|
)
|
|
widget.linkedWidgets = [controlWidget]
|
|
}
|
|
|
|
return widget
|
|
}
|
|
return widgetConstructor
|
|
}
|