[Bug] Fix number widget range not enforced (#850)

Resolves https://github.com/Comfy-Org/ComfyUI_frontend/issues/3204
This commit is contained in:
Chenlei Hu
2025-03-24 15:37:55 -04:00
committed by GitHub
parent 123c46d28b
commit c5db2d8736
2 changed files with 18 additions and 23 deletions

View File

@@ -113,6 +113,7 @@ export abstract class BaseWidget implements IBaseWidget {
}) {
const { node, canvas, e } = options
const oldValue = this.value
if (value === this.value) return
const v = this.type === "number" ? Number(value) : value
this.value = v

View File

@@ -19,6 +19,21 @@ export class NumberWidget extends BaseWidget implements INumericWidget {
this.value = widget.value
}
override setValue(value: number, options: {
e: CanvasMouseEvent
node: LGraphNode
canvas: LGraphCanvas
}) {
let newValue = value
if (this.options.min != null && newValue < this.options.min) {
newValue = this.options.min
}
if (this.options.max != null && newValue > this.options.max) {
newValue = this.options.max
}
super.setValue(newValue, options)
}
/**
* Draws the widget
* @param ctx The canvas context
@@ -111,16 +126,7 @@ export class NumberWidget extends BaseWidget implements INumericWidget {
if (delta) {
// Handle left/right arrow clicks
let newValue = this.value + delta * getWidgetStep(this.options)
if (this.options.min != null && newValue < this.options.min) {
newValue = this.options.min
}
if (this.options.max != null && newValue > this.options.max) {
newValue = this.options.max
}
if (newValue !== this.value) {
this.setValue(newValue, { e, node, canvas })
}
this.setValue(this.value + delta * getWidgetStep(this.options), { e, node, canvas })
return
}
@@ -159,18 +165,6 @@ export class NumberWidget extends BaseWidget implements INumericWidget {
: 0)
if (delta && (x > -3 && x < width + 3)) return
let newValue = this.value
if (e.deltaX) newValue += e.deltaX * getWidgetStep(this.options)
if (this.options.min != null && newValue < this.options.min) {
newValue = this.options.min
}
if (this.options.max != null && newValue > this.options.max) {
newValue = this.options.max
}
if (newValue !== this.value) {
this.setValue(newValue, { e, node, canvas })
}
this.setValue(this.value + (e.deltaX ?? 0) * getWidgetStep(this.options), { e, node, canvas })
}
}