@@ -63,13 +63,13 @@ public class SliderState(
63
63
* Internal value returned as fraction, used for displaying and specifying
64
64
* the "real" position of the thumb
65
65
*/
66
- internal val valueAsFraction: Float
67
- get() {
68
- val inverted = valueDistribution.inverse(value)
69
- val invertedRange = valueDistribution.inverse(range)
70
- return calcFraction(invertedRange.start, invertedRange.endInclusive, inverted)
66
+ internal val offsetAsFraction: Float
67
+ get() = if (totalWidth == 0f ) 0f else {
68
+ val valueFraction = value.valueToFraction(range)
69
+ valueDistribution.inverse(valueFraction)
71
70
}
72
71
72
+
73
73
internal val disabledRangeAsFractions: ClosedFloatingPointRange <Float >
74
74
get() = coerceRangeIntoFractions(disabledRange)
75
75
@@ -115,25 +115,18 @@ public class SliderState(
115
115
* Scales offset in to the value that user should see
116
116
*/
117
117
private fun scaleToUserValue (offset : Float ): Float {
118
- val invertedRange = valueDistribution.inverse(range)
119
- val value = scale(0f , totalWidth, offset, invertedRange.start, invertedRange.endInclusive)
120
- return coerceValue(valueDistribution.interpolate(value))
118
+
119
+ val value = valueDistribution.interpolate(offset / totalWidth)
120
+ .fractionToValue(range)
121
+ return coerceValue(value)
121
122
}
122
123
123
124
/* *
124
125
* Converts value of the user into the raw offset on the track
125
126
*/
126
127
private fun scaleToOffset (value : Float ): Float {
127
- val coerced = coerceValue(value)
128
- val invertedRange = valueDistribution.inverse(range)
129
- val invertedValue = valueDistribution.inverse(coerced)
130
- return scale(
131
- invertedRange.start,
132
- invertedRange.endInclusive,
133
- invertedValue,
134
- 0f ,
135
- totalWidth,
136
- )
128
+ val valueAsFraction = coerceValue(value).valueToFraction(range)
129
+ return valueDistribution.inverse(valueAsFraction).fractionToValue(0f , totalWidth)
137
130
}
138
131
139
132
internal fun coerceValue (value : Float ): Float {
@@ -156,17 +149,9 @@ public class SliderState(
156
149
subrange : ClosedFloatingPointRange <Float >,
157
150
): ClosedFloatingPointRange <Float > {
158
151
if (subrange.isEmpty()) return subrange
159
- val interpolatedRange = valueDistribution.interpolate(range)
160
- val interpolatedSubrange = valueDistribution.interpolate(subrange)
161
- return calcFraction(
162
- interpolatedRange.start,
163
- interpolatedRange.endInclusive,
164
- interpolatedSubrange.start,
165
- ).. calcFraction(
166
- interpolatedRange.start,
167
- interpolatedRange.endInclusive,
168
- interpolatedSubrange.endInclusive,
169
- )
152
+ val start = valueDistribution.inverse(subrange.start.valueToFraction(range))
153
+ val end = valueDistribution.inverse(subrange.endInclusive.valueToFraction(range))
154
+ return start.. end
170
155
}
171
156
}
172
157
0 commit comments