Setting Scrollbar Value Without Value Changed Event

Started by Ahnne Cognita, 10 September 2019, 14:49:44

Ahnne Cognita

Is it possible to set the value of a scrollbar without the Value Changed signal being triggered?

In my project, there's a situation where I need to do some validation before allowing the scrollbar's value to actually change. Currently, I'm using the Value Changed signal to begin the validation, but I haven't been able to find a way to force the scrollbar back to it's old value without triggering another Value Changed event.

Kvaz1r

Quote from: Ahnne Cognita on 10 September 2019, 14:49:44
Is it possible to set the value of a scrollbar without the Value Changed signal being triggered?
No, it's exactly purpose of the signal.

Quote from: Ahnne Cognita on 10 September 2019, 14:49:44
In my project, there's a situation where I need to do some validation before allowing the scrollbar's value to actually change. Currently, I'm using the Value Changed signal to begin the validation, but I haven't been able to find a way to force the scrollbar back to it's old value without triggering another Value Changed event.
There isn't any way to set custom validator to the control and check anything before changing. At least now, because it's really useful.
But I think you can bind your check to something else and make scrollbar disabled so one can't change it while state will not state as correct.

texus

I actually added a way to temporarily disable a signal some time ago just for this kind of situation.

Code (cpp) Select
scrollbar->onValueChange.setEnabled(false);
scrollbar->setValue(...);
scrollbar->onValueChange.setEnabled(true);

Ahnne Cognita

#3
Quote from: Kvaz1r on 10 September 2019, 18:21:35
Quote from: Ahnne Cognita on 10 September 2019, 14:49:44
In my project, there's a situation where I need to do some validation before allowing the scrollbar's value to actually change. Currently, I'm using the Value Changed signal to begin the validation, but I haven't been able to find a way to force the scrollbar back to it's old value without triggering another Value Changed event.
There isn't any way to set custom validator to the control and check anything before changing. At least now, because it's really useful.
But I think you can bind your check to something else and make scrollbar disabled so one can't change it while state will not state as correct.

Is it possible to bind to the underlying up/down button presses? I'm unable to disable the scrollbar entirely since the validation may only prevent one direction ie, still able to click/drag in the opposite. I could just use regular buttons and avoid the problem altogether.

Quote from: texus on 10 September 2019, 18:33:09
I actually added a way to temporarily disable a signal some time ago just for this kind of situation.

Code (cpp) Select
scrollbar->onValueChange.setEnabled(false);
scrollbar->setValue(...);
scrollbar->onValueChange.setEnabled(true);


Oh. Well that sounds wonderful. Thanks!  ;D

texus

QuoteIs it possible to bind to the underlying up/down button presses?
No, value changed signal is send for every kind of change, no matter whether a an up/down button is pressed, the mouse wheel is scrolled, the track is clicked or the thumb is dragged.

Kvaz1r

Quote from: texus on 10 September 2019, 18:33:09
I actually added a way to temporarily disable a signal some time ago just for this kind of situation.
That's indeed cool and rarely feature.

Quote from: Ahnne Cognita on 10 September 2019, 18:59:30
I'm unable to disable the scrollbar entirely since the validation may only prevent one direction ie, still able to click/drag in the opposite. I could just use regular buttons and avoid the problem altogether.
Right, it was a long shot.