mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-27 01:39:47 +00:00
[Refactor] Move Comfy.WidgetControlMode to coreSettings (#2078)
This commit is contained in:
@@ -67,6 +67,7 @@ import { useCommandStore } from '@/stores/commandStore'
|
|||||||
import { useWorkflowService } from '@/services/workflowService'
|
import { useWorkflowService } from '@/services/workflowService'
|
||||||
import { useColorPaletteStore } from '@/stores/workspace/colorPaletteStore'
|
import { useColorPaletteStore } from '@/stores/workspace/colorPaletteStore'
|
||||||
import { useColorPaletteService } from '@/services/colorPaletteService'
|
import { useColorPaletteService } from '@/services/colorPaletteService'
|
||||||
|
import { IS_CONTROL_WIDGET, updateControlWidgetLabel } from '@/scripts/widgets'
|
||||||
|
|
||||||
const emit = defineEmits(['ready'])
|
const emit = defineEmits(['ready'])
|
||||||
const canvasRef = ref<HTMLCanvasElement | null>(null)
|
const canvasRef = ref<HTMLCanvasElement | null>(null)
|
||||||
@@ -195,6 +196,23 @@ watchEffect(() => {
|
|||||||
LiteGraph.alwaysSnapToGrid = settingStore.get('pysssss.SnapToGrid')
|
LiteGraph.alwaysSnapToGrid = settingStore.get('pysssss.SnapToGrid')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
watch(settingStore.get('Comfy.WidgetControlMode'), () => {
|
||||||
|
for (const n of comfyApp.graph.nodes) {
|
||||||
|
if (!n.widgets) continue
|
||||||
|
for (const w of n.widgets) {
|
||||||
|
if (w[IS_CONTROL_WIDGET]) {
|
||||||
|
updateControlWidgetLabel(w)
|
||||||
|
if (w.linkedWidgets) {
|
||||||
|
for (const l of w.linkedWidgets) {
|
||||||
|
updateControlWidgetLabel(l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
comfyApp.graph.setDirtyCanvas(true)
|
||||||
|
})
|
||||||
|
|
||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
if (!canvasStore.canvas) return
|
if (!canvasStore.canvas) return
|
||||||
|
|
||||||
|
|||||||
@@ -679,5 +679,16 @@ export const CORE_SETTINGS: SettingParams[] = [
|
|||||||
type: 'hidden',
|
type: 'hidden',
|
||||||
defaultValue: {} as ColorPalettes,
|
defaultValue: {} as ColorPalettes,
|
||||||
versionModified: '1.6.7'
|
versionModified: '1.6.7'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'Comfy.WidgetControlMode',
|
||||||
|
category: ['Comfy', 'Node Widget', 'WidgetControlMode'],
|
||||||
|
name: 'Widget control mode',
|
||||||
|
tooltip:
|
||||||
|
'Controls when widget values are updated (randomize/increment/decrement), either before the prompt is queued or after.',
|
||||||
|
type: 'combo',
|
||||||
|
defaultValue: 'after',
|
||||||
|
options: ['before', 'after'],
|
||||||
|
versionModified: '1.6.10'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
// @ts-strict-ignore
|
// @ts-strict-ignore
|
||||||
import {
|
import { type ComfyWidgetConstructor, ComfyWidgets } from './widgets'
|
||||||
type ComfyWidgetConstructor,
|
|
||||||
ComfyWidgets,
|
|
||||||
initWidgets
|
|
||||||
} from './widgets'
|
|
||||||
import { ComfyUI, $el } from './ui'
|
import { ComfyUI, $el } from './ui'
|
||||||
import { api, type ComfyApi } from './api'
|
import { api, type ComfyApi } from './api'
|
||||||
import { defaultGraph } from './defaultGraph'
|
import { defaultGraph } from './defaultGraph'
|
||||||
@@ -1048,7 +1044,6 @@ export class ComfyApp {
|
|||||||
|
|
||||||
await useExtensionService().invokeExtensionsAsync('init')
|
await useExtensionService().invokeExtensionsAsync('init')
|
||||||
await this.registerNodes()
|
await this.registerNodes()
|
||||||
initWidgets(this)
|
|
||||||
|
|
||||||
// Load previous workflow
|
// Load previous workflow
|
||||||
let restored = false
|
let restored = false
|
||||||
|
|||||||
@@ -24,17 +24,20 @@ export type ComfyWidgetConstructor = (
|
|||||||
widgetName?: string
|
widgetName?: string
|
||||||
) => { widget: IWidget; minWidth?: number; minHeight?: number }
|
) => { widget: IWidget; minWidth?: number; minHeight?: number }
|
||||||
|
|
||||||
let controlValueRunBefore = false
|
function controlValueRunBefore() {
|
||||||
|
return useSettingStore().get('Comfy.WidgetControlMode') === 'before'
|
||||||
|
}
|
||||||
|
|
||||||
export function updateControlWidgetLabel(widget) {
|
export function updateControlWidgetLabel(widget) {
|
||||||
let replacement = 'after'
|
let replacement = 'after'
|
||||||
let find = 'before'
|
let find = 'before'
|
||||||
if (controlValueRunBefore) {
|
if (controlValueRunBefore()) {
|
||||||
;[find, replacement] = [replacement, find]
|
;[find, replacement] = [replacement, find]
|
||||||
}
|
}
|
||||||
widget.label = (widget.label ?? widget.name).replace(find, replacement)
|
widget.label = (widget.label ?? widget.name).replace(find, replacement)
|
||||||
}
|
}
|
||||||
|
|
||||||
const IS_CONTROL_WIDGET = Symbol()
|
export const IS_CONTROL_WIDGET = Symbol()
|
||||||
const HAS_EXECUTED = Symbol()
|
const HAS_EXECUTED = Symbol()
|
||||||
|
|
||||||
function getNumberDefaults(
|
function getNumberDefaults(
|
||||||
@@ -252,7 +255,7 @@ export function addValueControlWidgets(
|
|||||||
}
|
}
|
||||||
|
|
||||||
valueControl.beforeQueued = () => {
|
valueControl.beforeQueued = () => {
|
||||||
if (controlValueRunBefore) {
|
if (controlValueRunBefore()) {
|
||||||
// Don't run on first execution
|
// Don't run on first execution
|
||||||
if (valueControl[HAS_EXECUTED]) {
|
if (valueControl[HAS_EXECUTED]) {
|
||||||
applyWidgetControl()
|
applyWidgetControl()
|
||||||
@@ -262,7 +265,7 @@ export function addValueControlWidgets(
|
|||||||
}
|
}
|
||||||
|
|
||||||
valueControl.afterQueued = () => {
|
valueControl.afterQueued = () => {
|
||||||
if (!controlValueRunBefore) {
|
if (!controlValueRunBefore()) {
|
||||||
applyWidgetControl()
|
applyWidgetControl()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -465,36 +468,6 @@ function isSlider(display, app) {
|
|||||||
return display === 'slider' ? 'slider' : 'number'
|
return display === 'slider' ? 'slider' : 'number'
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initWidgets(app) {
|
|
||||||
app.ui.settings.addSetting({
|
|
||||||
id: 'Comfy.WidgetControlMode',
|
|
||||||
category: ['Comfy', 'Node Widget', 'WidgetControlMode'],
|
|
||||||
name: 'Widget control mode',
|
|
||||||
tooltip:
|
|
||||||
'Controls when widget values are updated (randomize/increment/decrement), either before the prompt is queued or after.',
|
|
||||||
type: 'combo',
|
|
||||||
defaultValue: 'after',
|
|
||||||
options: ['before', 'after'],
|
|
||||||
onChange(value) {
|
|
||||||
controlValueRunBefore = value === 'before'
|
|
||||||
for (const n of app.graph.nodes) {
|
|
||||||
if (!n.widgets) continue
|
|
||||||
for (const w of n.widgets) {
|
|
||||||
if (w[IS_CONTROL_WIDGET]) {
|
|
||||||
updateControlWidgetLabel(w)
|
|
||||||
if (w.linkedWidgets) {
|
|
||||||
for (const l of w.linkedWidgets) {
|
|
||||||
updateControlWidgetLabel(l)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
app.graph.setDirtyCanvas(true)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ComfyWidgets: Record<string, ComfyWidgetConstructor> = {
|
export const ComfyWidgets: Record<string, ComfyWidgetConstructor> = {
|
||||||
'INT:seed': seedWidget,
|
'INT:seed': seedWidget,
|
||||||
'INT:noise_seed': seedWidget,
|
'INT:noise_seed': seedWidget,
|
||||||
|
|||||||
Reference in New Issue
Block a user