interface.js icon indicating copy to clipboard operation
interface.js copied to clipboard

set value dynamically

Open aferriss opened this issue 7 years ago • 2 comments

Is there a good way to set a widget's value at runtime and have the ui update accordingly? I see there is a setValue() function in the widget prototype, but accessing it doesn't seem to do anything.

var newVal = 0.2;
panel.myCrossFader.__proto__.setValue(newVal, false);
//changes __proto__.value

Nor does just setting the value directly

panel.myCrossFader.value = newVal;
// changes myCrossFader.value

The value does seem to change if I log it, but the ui doesn't update to display the change. I tried calling panel.refresh(), but again, no effect.

Also not really sure what the changeValue function is meant to be doing. I tried using that as well but again, no change.

panel.myCrossFader.changeValue(newVal, newVal);

Any ideas?

aferriss avatar Feb 28 '17 20:02 aferriss

Actually I just realized that the changeValue function does work, but you need to force .hasFocus to be true, however this causes other problems, as then the slider is always active and following the mouse.

aferriss avatar Feb 28 '17 20:02 aferriss

Alright, got this working, just ended up writing my own setValue method for the crossFader. Maybe there's a better way but this seems to work.

setValue: function(val){
   this._value = val;
   this.refresh();
},

aferriss avatar Feb 28 '17 20:02 aferriss