Slider and checkbox 'onValue' observables (place for improvement or did I miss something?)

Dears,
It seem odd to say, but I continue to face challenges using the BJS GUI. Looks like until today I didn’t really have to worry about the behavior of checkboxes or sliders.
But right now, I’m creating a more ‘evolved’ Editor and I have some issues (question actually) regarding the ‘onValueChanged’ observables for these controls.
Basically, I believe it is something common, I have two ways of changing the state or value of these controls:

  1. setting it through the control itself. User checks the box or user moves the slider and the value is applied.

  2. User does not check or move the slider but the value or state is applied through the function (as the initial value).

Now, I’ve been going through the observables for these controls - and - (again, might just be missing something) but, to me, the ‘onValueChanged’ observable kind of doesn’t seem 100% accurate. Currently, I have functions triggered when the user changes this value/state BUT I don’t want these to trigger when the value is set programmaticaly. Of course, as always, there’s a work-around (and may be I don’t even have the right one)… but with all that said, I’m still thinking:
"Wouldn’t it make sense to be able to differentiate when the value or state is set/changed through user interaction and when it isn’t?". May be something like:

  • ‘OnValueSetObservable’, when the value is set to initial, programmatically
  • ‘OnValueChangedObservable’, when the value is actually set through user interaction
    ?

I’d appreciate your input and comments (and feel free to LOL me if I obviously missed something :face_with_hand_over_mouth: :grin:)

Meanwhile, have a great day :sunglasses:

Hello :slight_smile:

Regardless of BabylonJS itself, it’s quite common (at least to me) to have an observable on a value you may programmatically change at some point. What I use to do is like :

let listen = true;
input.onValueChanged(()=>{
    if(listen){
        // Do your stuff
    }
})

And eventually later when I need to programmatically change :

listen = false;
input.value = newValue;
listen = true;

Which you could have wrapped into a setter :

function set(value){
    listen = false;
    input.value = value;
    listen = true;
}

etc…


To me having an observable of a “programmatically” set value would be useless since you already know when it’s set : when you set it… :thinking:

++ :slight_smile:
Tricotou

1 Like

Yes, that’s basically what I’m doing :grin:

As i said, could just be ‘lazy me’ :grin: :face_with_hand_over_mouth: :joy:
I don’t really have an issue with it :grin:

Edit: I’m actually using the pointerDown and *Up observables for the listener… this way I don’t have to add anything when setting programatically. It’s not as if we wouldn’t have enough ‘flexibility’ for BYO :grin:… I’m probably just very tired, thus seeking ‘minimal effort’ these days. It should be better in a few days… hopefully :sweat_smile: :joy: