[DO NOT USE] Show Integer in slider
This commit is contained in:
1 parent
13e5649948
commit
8efc5401cb
3 files changed
+5
-3
No files matched your search
@@ -154,7 +154,7 @@ fun EhScreen() {
|
||||
IntSliderPreference(
|
||||
maxValue = 400,
|
||||
minValue = 80,
|
||||
step = 3,
|
||||
step = 7,
|
||||
title = stringResource(id = R.string.settings_eh_thumb_size),
|
||||
value = Settings::thumbSizeDp,
|
||||
)
|
||||
|
||||
@@ -93,7 +93,7 @@ fun SwitchPreference(title: String, summary: String? = null, value: KMutableProp
|
||||
fun IntSliderPreference(maxValue: Int, minValue: Int = 0, step: Int = maxValue - minValue - 1, title: String, value: KMutableProperty0<Int>, enabled: Boolean = true) {
|
||||
var v by remember { mutableIntStateOf(value.get()) }
|
||||
fun set(float: Float) = value.set(float.roundToInt().also { v = it })
|
||||
SliderPref(title = title, defaultValue = v.toFloat(), onValueChangeFinished = ::set, valueRange = minValue.toFloat()..maxValue.toFloat(), showValue = true, steps = step, enabled = enabled)
|
||||
SliderPref(title = title, defaultValue = v.toFloat(), onValueChangeFinished = ::set, valueRange = minValue.toFloat()..maxValue.toFloat(), showValue = true, showInteger = true, steps = step, enabled = enabled)
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
@@ -18,6 +18,7 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.jamal.composeprefs3.ui.roundToDP
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@Composable
|
||||
fun SliderPref(
|
||||
@@ -27,6 +28,7 @@ fun SliderPref(
|
||||
onValueChangeFinished: ((Float) -> Unit)? = null,
|
||||
valueRange: ClosedFloatingPointRange<Float> = 0f..1f,
|
||||
showValue: Boolean = false,
|
||||
showInteger: Boolean = false,
|
||||
steps: Int = 0,
|
||||
textColor: Color = MaterialTheme.colorScheme.onBackground,
|
||||
enabled: Boolean = true,
|
||||
@@ -60,7 +62,7 @@ fun SliderPref(
|
||||
)
|
||||
if (showValue) {
|
||||
Text(
|
||||
text = roundToDP(value, 2).toString(),
|
||||
text = if (showInteger) value.roundToInt().toString() else roundToDP(value, 2).toString(),
|
||||
color = textColor,
|
||||
modifier = Modifier.weight(0.5f).padding(start = 8.dp),
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user