pharo-spec / Spec

Spec is a framework in Pharo for describing user interfaces.
MIT License
62 stars 65 forks source link

SpSliderPresenter doesn't behave well. Dragging it makes the handle jump erratic between min and max value #1595

Open ironirc opened 2 months ago

ironirc commented 2 months ago

A possible resolution might be following method change.

SpMorphicSliderAdapter>>#buildWidget ... self presenter whenValueChangedDo: [ :newValue | preWidget value: self absoluteValue ]. ...

In other words, the preWidget value should be set with the absoluteValue (instead of using newValue)

antonello-chessa commented 2 months ago

Yes @ironirc, your conclusion matches the results I found by doing some tests. I modified SliderMorph>>value: adding the following diagnostic instruction: Transcript show:('SliderMorph value: sent with:{1} by {2}'format:{newValue . thisContext sender});cr. And it shows that the wrong value is assigned by the block assigned to self presenter whenValueChangedDo: whitin SpMorphicSliderAdapter>>buildWidget. The issue was indeed that the value needed to be converted to absolute value(which is the ratio (value-min)/(max-min) with values in [0,1]). Without that conversion the instruction in:

SliderMorph>>value: newValue
   ...
   value := newValue min:1 max:0.
   ...

would truncate the value of newValue to 1 and then assign it to value causing the thumb to be drawn on the right at the position associated to the highest slider value. That was the cause of the erratic behavior of the thumb, because, both when clicking and dragging it was jumping between being drawn at the end of the slider and at the correct position.

Ducasse commented 2 months ago

Hi guys Thank you for opening this issue. We will have a look.