Skip to content

Commit

Permalink
Fix widget changed callback not called
Browse files Browse the repository at this point in the history
  • Loading branch information
webfiltered committed Nov 22, 2024
1 parent 1f572b4 commit 756ae35
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/LGraphCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2534,13 +2534,14 @@ export class LGraphCanvas {
: 0
pointer.onClick = (upEvent) => {
// Left/right arrows
widget.value += delta * 0.1 * (widget.options.step || 1)
if (widget.options.min != null && widget.value < widget.options.min) {
widget.value = widget.options.min
let newValue = widget.value + delta * 0.1 * (widget.options.step || 1)
if (widget.options.min != null && newValue < widget.options.min) {
newValue = widget.options.min
}
if (widget.options.max != null && widget.value > widget.options.max) {
widget.value = widget.options.max
if (widget.options.max != null && newValue > widget.options.max) {
newValue = widget.options.max
}
if (newValue !== widget.value) setWidgetValue(this, node, widget, newValue)

if (delta !== 0) return

Expand All @@ -2564,14 +2565,16 @@ export class LGraphCanvas {
const x = eMove.canvasX - node.pos[0]
if (delta && (x > -3 && x < width + 3)) return

if (eMove.deltaX) widget.value += eMove.deltaX * 0.1 * (widget.options.step || 1)
let newValue = widget.value
if (eMove.deltaX) newValue += eMove.deltaX * 0.1 * (widget.options.step || 1)

if (widget.options.min != null && widget.value < widget.options.min) {
widget.value = widget.options.min
if (widget.options.min != null && newValue < widget.options.min) {
newValue = widget.options.min
}
if (widget.options.max != null && widget.value > widget.options.max) {
widget.value = widget.options.max
if (widget.options.max != null && newValue > widget.options.max) {
newValue = widget.options.max
}
if (newValue !== widget.value) setWidgetValue(this, node, widget, newValue)
}
break
}
Expand Down Expand Up @@ -2679,6 +2682,9 @@ export class LGraphCanvas {
node.setProperty(widget.options.property, v)
}
widget.callback?.(widget.value, canvas, node, pos, e)

node.onWidgetChanged?.(widget.name, v, oldValue, widget)
node.graph._version++
}
}

Expand Down

0 comments on commit 756ae35

Please sign in to comment.