Compare commits
1 Commits
develop
...
feature/IS
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1fc9640e38 |
@@ -334,7 +334,7 @@ fun DcdSettingPopup(
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxHeight()
|
.fillMaxHeight()
|
||||||
.size(40.px.dp, 210.px.dp),
|
.size(40.px.dp, 210.px.dp),
|
||||||
chargeRate = gasChargeRate.toInt()
|
chargeRate = gasChargeRate
|
||||||
)
|
)
|
||||||
|
|
||||||
// Icon
|
// Icon
|
||||||
|
|||||||
@@ -28,14 +28,26 @@ import com.laseroptek.raman.ui.screens.main.MainViewModel
|
|||||||
import com.laseroptek.raman.utils.DefaultDispatcherProvider
|
import com.laseroptek.raman.utils.DefaultDispatcherProvider
|
||||||
import com.laseroptek.raman.utils.ext.px
|
import com.laseroptek.raman.utils.ext.px
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
import kotlin.math.abs
|
||||||
|
import kotlin.math.ceil
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun GradientSlider(
|
fun GradientSlider(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
chargeRate: Int = 0, // Value from (0 .. 100)
|
chargeRate: Float = 0f,
|
||||||
) {
|
) {
|
||||||
val chargeIndex = ((chargeRate.coerceIn(0, 100) + 4) / 5).toInt() // 0..19
|
val normalizedRate = chargeRate.coerceIn(0f, 100f)
|
||||||
|
val bucket = normalizedRate / 5f
|
||||||
|
val remainder = normalizedRate % 5f
|
||||||
|
val isExactMultiple = abs(remainder) < 0.0001f
|
||||||
|
|
||||||
|
val chargeIndex = when {
|
||||||
|
normalizedRate == 0f -> -1
|
||||||
|
isExactMultiple -> (bucket - 1f).toInt().coerceAtLeast(-1)
|
||||||
|
else -> (ceil(bucket.toDouble()).toInt() - 1)
|
||||||
|
}.coerceIn(-1, 19)
|
||||||
|
|
||||||
Timber.d("chargeRate: $chargeRate, chargeIndex: $chargeIndex")
|
Timber.d("chargeRate: $chargeRate, chargeIndex: $chargeIndex")
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
@@ -103,6 +115,6 @@ fun GradientSliderPreview(
|
|||||||
//mainViewModel = mainViewModel
|
//mainViewModel = mainViewModel
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(40.px.dp, 210.px.dp),
|
.size(40.px.dp, 210.px.dp),
|
||||||
chargeRate = 20
|
chargeRate = 20f
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user