mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 11:11:53 +00:00
[Bug] Fix number widget range not enforced (#850)
Resolves https://github.com/Comfy-Org/ComfyUI_frontend/issues/3204
This commit is contained in:
@@ -113,6 +113,7 @@ export abstract class BaseWidget implements IBaseWidget {
|
|||||||
}) {
|
}) {
|
||||||
const { node, canvas, e } = options
|
const { node, canvas, e } = options
|
||||||
const oldValue = this.value
|
const oldValue = this.value
|
||||||
|
if (value === this.value) return
|
||||||
|
|
||||||
const v = this.type === "number" ? Number(value) : value
|
const v = this.type === "number" ? Number(value) : value
|
||||||
this.value = v
|
this.value = v
|
||||||
|
|||||||
@@ -19,6 +19,21 @@ export class NumberWidget extends BaseWidget implements INumericWidget {
|
|||||||
this.value = widget.value
|
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
|
* Draws the widget
|
||||||
* @param ctx The canvas context
|
* @param ctx The canvas context
|
||||||
@@ -111,16 +126,7 @@ export class NumberWidget extends BaseWidget implements INumericWidget {
|
|||||||
|
|
||||||
if (delta) {
|
if (delta) {
|
||||||
// Handle left/right arrow clicks
|
// Handle left/right arrow clicks
|
||||||
let newValue = this.value + delta * getWidgetStep(this.options)
|
this.setValue(this.value + delta * getWidgetStep(this.options), { e, node, canvas })
|
||||||
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 })
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,18 +165,6 @@ export class NumberWidget extends BaseWidget implements INumericWidget {
|
|||||||
: 0)
|
: 0)
|
||||||
|
|
||||||
if (delta && (x > -3 && x < width + 3)) return
|
if (delta && (x > -3 && x < width + 3)) return
|
||||||
|
this.setValue(this.value + (e.deltaX ?? 0) * getWidgetStep(this.options), { e, node, canvas })
|
||||||
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 })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user