Skip to content

Commit 256a67b

Browse files
committed
docs(Slider): Add kdoc for the public apis
1 parent eb7ea72 commit 256a67b

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

slider/src/main/java/io/monstarlab/mosaic/slider/Slider.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ import androidx.compose.ui.platform.LocalLayoutDirection
1515
import androidx.compose.ui.tooling.preview.Preview
1616
import androidx.compose.ui.unit.LayoutDirection
1717

18+
/**
19+
* A composable function that creates a slider UI component.
20+
*
21+
* @param value the current value of the slider
22+
* @param onValueChange a callback function invoked when the slider value changes
23+
* @param colors the colors used to customize the appearance of the slider
24+
* @param modifier the modifier to be applied to the slider
25+
* @param valueDistribution the strategy for distributing slider values
26+
* @param range the range of values the slider can represent
27+
* @param interactionSource the interaction source used to handle user input interactions
28+
* @param thumb the composable function used to render the slider thumb
29+
*/
1830
@Composable
1931
public fun Slider(
2032
value: Float,

slider/src/main/java/io/monstarlab/mosaic/slider/SliderState.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import androidx.compose.runtime.remember
1212
import androidx.compose.runtime.setValue
1313
import kotlinx.coroutines.coroutineScope
1414

15+
/**
16+
* A compose state for the Slider component
17+
* Responsible for managing internal properties such as offset value and drag / click behaviours
18+
*/
1519
public class SliderState(
1620
value: Float,
1721
private val valueDistribution: SliderValueDistribution,
@@ -32,10 +36,14 @@ public class SliderState(
3236
return calcFraction(0f, totalWidth, rawOffset)
3337
}
3438

39+
/**
40+
* Current value of the slider
41+
* If value of the slider is out of the [range] it will be coerced into it
42+
*/
3543
public var value: Float
36-
get() = scaleToUserValue(rawOffset)
44+
get() = scaleToUserValue(rawOffset).coerceIn(range)
3745
set(value) {
38-
rawOffset = scaleToOffset(value)
46+
rawOffset = scaleToOffset(value.coerceIn(range))
3947
}
4048

4149
private val dragScope: DragScope = object : DragScope {

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,47 @@ package io.monstarlab.mosaic.slider
22

33
import kotlin.math.sqrt
44

5+
/**
6+
* Determines how the values will be distributed across the slider
7+
* Usually the values are distributed in a linear fashion, this interfaces allows
8+
* to control the distribution using simple math expressions
9+
* @see ParabolicValueDistribution to see how values can be distributed using parabolic curve
10+
*/
511
public interface SliderValueDistribution {
612

13+
/**
14+
* Interpolates a value based on the distribution strategy.
15+
* @param value the input value to interpolate
16+
* @return the interpolated value based on the distribution strategy
17+
*/
718
public fun interpolate(value: Float): Float
819

20+
/**
21+
* Inversely interpolates a value from the output range to the input range based on the distribution strategy.
22+
*
23+
* @param value the output value to inverse interpolate
24+
* @return the inverse interpolated value based on the distribution strategy
25+
*/
926
public fun inverse(value: Float): Float
1027

1128
public companion object {
1229

30+
/**
31+
* Creates a [SliderValueDistribution] with a parabolic distribution strategy.
32+
*
33+
* @param a coefficient of the x^2 term in the parabolic equation
34+
* @param b coefficient of the x term in the parabolic equation
35+
* @param c constant term in the parabolic equation
36+
* @return a [SliderValueDistribution] instance with a parabolic distribution strategy
37+
*/
1338
public fun parabolic(a: Float, b: Float, c: Float): SliderValueDistribution {
1439
return ParabolicValueDistribution(a, b, c)
1540
}
1641

42+
/**
43+
* A linear distribution strategy where the input value is directly mapped to the output value.
44+
* Used in [Slider] by default
45+
*/
1746
public val Linear: SliderValueDistribution = object : SliderValueDistribution {
1847
override fun interpolate(value: Float): Float {
1948
return value
@@ -26,6 +55,18 @@ public interface SliderValueDistribution {
2655
}
2756
}
2857

58+
59+
/**
60+
* Represents a parabolic distribution strategy for slider values.
61+
*
62+
* This strategy calculates interpolated and inversely interpolated values based on a parabolic equation:
63+
* f(x) = a * x^2 + b * x + c
64+
*
65+
* @property a coefficient of the x^2 term in the parabolic equation
66+
* @property b coefficient of the x term in the parabolic equation
67+
* @property c constant term in the parabolic equation
68+
* @constructor Creates a ParabolicValueDistribution with the given coefficients.
69+
*/
2970
public class ParabolicValueDistribution(
3071
private val a: Float,
3172
private val b: Float,

0 commit comments

Comments
 (0)