HamzaGhazouani/HGCircularSlider

Setting end point value to max value causes track to reset to unfilled

jessemx109 opened this issue · 4 comments

When you set the end point to the max value the track resets to the zero state. Expected behavior would be for the track to be fully filled in to match 100% completed.

I looked at the source briefly and in the scaleValue function there is some division that is returning 0 when the value should be 1 which may be causing the problem

I have faced the same issue.

A quick solution would be to edit func draw(_ rect: CGRect) in CircularSlider.

// get end angle from end value
var endAngle = CircularSliderHelper.scaleToAngle(value: endPointValue, inInterval: valuesInterval) + CircularSliderHelper.circleInitialAngle

if endPointValue == maximumValue {
  endAngle = CircularSliderHelper.circleMaxValue + CircularSliderHelper.circleInitialAngle
} else if endPointValue == minimumValue {
  endAngle = CircularSliderHelper.circleInitialAngle
}

Fixed in #56

A quick solution would be to edit func newValue(from oldValue: CGFloat, touch touchPosition: CGPoint, start startPosition: CGPoint) in CircularSlider.

 //Instead of fixing range with maximum or minimum value, if new value exceed maximum/minimum, keep it fixed there. 

  var newValue = oldValue + deltaValue
    
    if newValue > maximumValue {
        newValue = maximumValue
    }
    else if newValue < minimumValue {
        newValue = minimumValue
    }
    return newValue