Skip to content

Commit 2dda459

Browse files
committed
feat: add SliderValue Distribution builder for checkpoint inside cmpanion object
1 parent d5a80dc commit 2dda459

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

slider/src/main/java/io/monstarlab/mosaic/slider/distribution/SliderValueDistribution.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@ public interface SliderValueDistribution {
3939
return ParabolicValueDistribution(a, b, c)
4040
}
4141

42+
/**
43+
* Creates a [SliderValueDistribution] with a distribution strategy based on a list of check points.
44+
* Each check point is a pair of offset fraction and value that will be associated with with this progress
45+
* The distribution will interpolate between the check points using linear equations.
46+
*
47+
* Example:
48+
* For the value range of 0..100
49+
* CheckPointsValueDistribution(listOf(0f to 0f, 0.5f to 80f, 1f to 100f))
50+
* This will create a distribution that will place value of 80 at 0.5 progress allowing the user to
51+
* have more precision while selecting values between 80 and 100
52+
*
53+
* @param values a list of check points, each check point is a pair of offset fraction and value
54+
* @return a [SliderValueDistribution] instance with a check points distribution strategy
55+
*/
56+
public fun checkpoints(vararg values: Pair<Float, Float>): SliderValueDistribution {
57+
return CheckPointsValueDistribution(values.toList())
58+
}
59+
4260
/**
4361
* A linear distribution strategy where the input value is directly mapped to the output value.
4462
* Used in [Slider] by default

0 commit comments

Comments
 (0)