From db4116b43793e9c3d9599cc7a747172229417fc6 Mon Sep 17 00:00:00 2001 From: Smart Tool Factory Date: Fri, 8 Apr 2022 11:18:25 +0300 Subject: [PATCH] refactor --- README.md | 5 +++-- .../java/com/smarttoolfactory/slider/ColorfulIconSlider.kt | 6 +++--- .../main/java/com/smarttoolfactory/slider/ColorfulSlider.kt | 2 +- .../main/java/com/smarttoolfactory/slider/DimensionUtil.kt | 6 +++--- .../main/java/com/smarttoolfactory/slider/MinimumTouch.kt | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d0f352c..5557888 100644 --- a/README.md +++ b/README.md @@ -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 | | ----------|-----------| -----------| -----------| -----------| -| | | | | | +| | | | | | ### ColorfulSlider @@ -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, diff --git a/slider/src/main/java/com/smarttoolfactory/slider/ColorfulIconSlider.kt b/slider/src/main/java/com/smarttoolfactory/slider/ColorfulIconSlider.kt index 032c338..8e5566c 100644 --- a/slider/src/main/java/com/smarttoolfactory/slider/ColorfulIconSlider.kt +++ b/slider/src/main/java/com/smarttoolfactory/slider/ColorfulIconSlider.kt @@ -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) @@ -465,7 +466,6 @@ private fun SliderComposeLayout( it.measure(constraints) }.first() - val sliderWidth = sliderPlaceable.width val sliderHeight = sliderPlaceable.height @@ -473,4 +473,4 @@ private fun SliderComposeLayout( sliderPlaceable.placeRelative(0, 0) } } -} \ No newline at end of file +} diff --git a/slider/src/main/java/com/smarttoolfactory/slider/ColorfulSlider.kt b/slider/src/main/java/com/smarttoolfactory/slider/ColorfulSlider.kt index 74bfd76..cc49dc1 100644 --- a/slider/src/main/java/com/smarttoolfactory/slider/ColorfulSlider.kt +++ b/slider/src/main/java/com/smarttoolfactory/slider/ColorfulSlider.kt @@ -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 ) } diff --git a/slider/src/main/java/com/smarttoolfactory/slider/DimensionUtil.kt b/slider/src/main/java/com/smarttoolfactory/slider/DimensionUtil.kt index 308a339..e314aa0 100644 --- a/slider/src/main/java/com/smarttoolfactory/slider/DimensionUtil.kt +++ b/slider/src/main/java/com/smarttoolfactory/slider/DimensionUtil.kt @@ -7,7 +7,7 @@ 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) } @@ -15,13 +15,13 @@ fun lerp(start: Float, end: Float, amount: Float): Float { * 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, diff --git a/slider/src/main/java/com/smarttoolfactory/slider/MinimumTouch.kt b/slider/src/main/java/com/smarttoolfactory/slider/MinimumTouch.kt index b930f18..52c8fef 100644 --- a/slider/src/main/java/com/smarttoolfactory/slider/MinimumTouch.kt +++ b/slider/src/main/java/com/smarttoolfactory/slider/MinimumTouch.kt @@ -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"