Skip to content

Commit 0d870bb

Browse files
committed
docs(Slider): Add some more kdoc comments
1 parent 5b96b5d commit 0d870bb

File tree

2 files changed

+58
-25
lines changed

2 files changed

+58
-25
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,41 @@ import androidx.compose.runtime.Immutable
44
import androidx.compose.runtime.Stable
55
import androidx.compose.ui.graphics.Color
66

7+
/**
8+
* Colors of the slider
9+
*/
710
@Immutable
811
public class SliderColors(
12+
/**
13+
* Color of the active track representing the track to the start of the thumb
14+
*/
915
public val activeTrackColor: Color,
16+
/**
17+
* Represents the color of the disabled range,
18+
* where user is not able to put a thumb to
19+
*/
1020
public val disabledRangeTrackColor: Color = activeTrackColor,
21+
/**
22+
* Color of the Inactive track, to the end of the thumb
23+
*/
1124
public val inactiveTrackColor: Color = activeTrackColor.copy(alpha = 0.5f),
25+
/**
26+
* Active track color when the Slider is disabled and user can't interact with it
27+
*/
1228
public val disabledActiveTrackColor: Color = activeTrackColor.copy(alpha = 0.2f),
29+
/**
30+
* Color of the Inactive track when the Slider is disabled
31+
*/
1332
public val disabledInactiveTrackColor: Color = activeTrackColor.copy(alpha = 0.2f),
33+
/**
34+
* Color of the thumb
35+
* only applied when the default thumb is used
36+
*/
1437
public val thumbColor: Color = activeTrackColor,
38+
/**
39+
* Color of the thumb when the Slider is disabled
40+
* Only applied when the default thumb is used
41+
*/
1542
public val disabledThumbColor: Color = disabledRangeTrackColor,
1643
) {
1744
@Stable

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

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public class SliderState(
5454
*
5555
*/
5656
public var value: Float
57-
get() = valueState.coerceIntoDisabledRange()
57+
get() = valueState
5858
set(value) {
59-
valueState = value.coerceIntoDisabledRange()
59+
valueState = coerceValue(value)
6060
}
6161

6262
/**
@@ -110,35 +110,18 @@ public class SliderState(
110110
}
111111
}
112112

113-
internal fun coerceValue(value: Float): Float {
114-
return value
115-
.coerceIn(range)
116-
.coerceIntoDisabledRange()
117-
}
118-
119-
private fun coerceRangeIntoFractions(
120-
subrange: ClosedFloatingPointRange<Float>,
121-
): ClosedFloatingPointRange<Float> {
122-
if (subrange.isEmpty()) return subrange
123-
val interpolatedRange = valueDistribution.interpolate(range)
124-
val interpolatedSubrange = valueDistribution.interpolate(subrange)
125-
return calcFraction(
126-
interpolatedRange.start,
127-
interpolatedRange.endInclusive,
128-
interpolatedSubrange.start,
129-
)..calcFraction(
130-
interpolatedRange.start,
131-
interpolatedRange.endInclusive,
132-
interpolatedSubrange.endInclusive,
133-
)
134-
}
135-
113+
/**
114+
* Scales offset in to the value that user should see
115+
*/
136116
private fun scaleToUserValue(offset: Float): Float {
137117
val range = valueDistribution.interpolate(range)
138118
val scaledUserValue = scale(0f, totalWidth, offset, range.start, range.endInclusive)
139119
return coerceValue(valueDistribution.inverse(scaledUserValue))
140120
}
141121

122+
/**
123+
* Converts value of the user into the raw offset on the track
124+
*/
142125
private fun scaleToOffset(value: Float): Float {
143126
val coerced = coerceValue(value)
144127
val interpolatedRange = valueDistribution.interpolate(range)
@@ -152,6 +135,12 @@ public class SliderState(
152135
)
153136
}
154137

138+
internal fun coerceValue(value: Float): Float {
139+
return value
140+
.coerceIn(range)
141+
.coerceIntoDisabledRange()
142+
}
143+
155144
private fun Float.coerceIntoDisabledRange(): Float {
156145
if (disabledRange.isEmpty()) return this
157146
// check if disabled range is on the left or right
@@ -161,6 +150,23 @@ public class SliderState(
161150
coerceAtMost(disabledRange.start)
162151
}
163152
}
153+
154+
private fun coerceRangeIntoFractions(
155+
subrange: ClosedFloatingPointRange<Float>,
156+
): ClosedFloatingPointRange<Float> {
157+
if (subrange.isEmpty()) return subrange
158+
val interpolatedRange = valueDistribution.interpolate(range)
159+
val interpolatedSubrange = valueDistribution.interpolate(subrange)
160+
return calcFraction(
161+
interpolatedRange.start,
162+
interpolatedRange.endInclusive,
163+
interpolatedSubrange.start,
164+
)..calcFraction(
165+
interpolatedRange.start,
166+
interpolatedRange.endInclusive,
167+
interpolatedSubrange.endInclusive,
168+
)
169+
}
164170
}
165171

166172
@Composable

0 commit comments

Comments
 (0)