Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
SmartToolFactory committed Apr 8, 2022
1 parent 5a82782 commit db4116b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Colorful sliders that can have Solid or Gradient colors for thumb or track which
track with varying sizes, borders with solid or gradient colors. And Sliders with emojis, or custom
Composables like **Icon**.

|Dimensions | Properties | Slider with Icon | Slider with Label | Gradient |
|Properties | Dimensions | Slider with Icon | Slider with Label | Gradient |
| ----------|-----------| -----------| -----------| -----------|
| <img src="./screenshots/slider_dimensions.png"/> | <img src="./screenshots/slider_properties.png"/> | <img src="./screenshots/slider_icons.png"/> | <img src="./screenshots/slider_labels.png"/> | <img src="./screenshots/slider_gradient.png"/> |
| <img src="./screenshots/slider_properties.png"/> | <img src="./screenshots/slider_dimensions.png"/> | <img src="./screenshots/slider_icons.png"/> | <img src="./screenshots/slider_labels.png"/> | <img src="./screenshots/slider_gradient.png"/> |

### ColorfulSlider

Expand Down Expand Up @@ -198,6 +198,7 @@ fun ColorfulIconSlider(

Usage

Emojis are transparent by default in Compose, you might want to set non-transparent color for `Text`
```
ColorfulIconSlider(
value = progress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ fun ColorfulIconSlider(
minWidth = ThumbRadius * 2,
minHeight = ThumbRadius * 2,
),
thumb = { thumb() }) { thumbSize: IntSize, constraints: Constraints ->
thumb = { thumb() }
) { thumbSize: IntSize, constraints: Constraints ->

require(steps >= 0) { "steps should be >= 0" }
val onValueChangeState = rememberUpdatedState(onValueChange)
Expand Down Expand Up @@ -465,12 +466,11 @@ private fun SliderComposeLayout(
it.measure(constraints)
}.first()


val sliderWidth = sliderPlaceable.width
val sliderHeight = sliderPlaceable.height

layout(sliderWidth, sliderHeight) {
sliderPlaceable.placeRelative(0, 0)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ private fun Track(
pointMode = PointMode.Points,
brush = if (outsideFraction) inactiveTickColor
else activeTickColor,
strokeRadius.coerceAtMost(thumbRadius / 2),
strokeWidth = strokeRadius.coerceAtMost(thumbRadius / 2),
cap = StrokeCap.Round
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ package com.smarttoolfactory.slider
* @param end of interval
* @param amount e closed unit interval [0, 1]
*/
fun lerp(start: Float, end: Float, amount: Float): Float {
internal fun lerp(start: Float, end: Float, amount: Float): Float {
return (1 - amount) * start + amount * (end - start)
}

/**
* Scale x1 from start1..end1 range to start2..end2 range
*/
fun scale(start1: Float, end1: Float, pos: Float, start2: Float, end2: Float) =
internal fun scale(start1: Float, end1: Float, pos: Float, start2: Float, end2: Float) =
lerp(start2, end2, calculateFraction(start1, end1, pos))

/**
* Scale x.start, x.endInclusive from a1..b1 range to a2..b2 range
*/
fun scale(
internal fun scale(
start1: Float,
end1: Float,
range: ClosedFloatingPointRange<Float>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import kotlin.math.roundToInt

@OptIn(ExperimentalMaterialApi::class)
@Suppress("ModifierInspectorInfo")
fun Modifier.minimumTouchTargetSize(): Modifier = composed(
internal fun Modifier.minimumTouchTargetSize(): Modifier = composed(
inspectorInfo = debugInspectorInfo {
name = "minimumTouchTargetSize"

Expand Down

0 comments on commit db4116b

Please sign in to comment.