Skip to content

Commit

Permalink
Merge pull request #4458 from Abhinavreddy-B/enhanced-slider
Browse files Browse the repository at this point in the history
Enhanced slider
  • Loading branch information
fast4x authored Nov 11, 2024
2 parents 51e4c51 + b62177d commit d19a27f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import it.fast4x.rimusic.utils.secondary
import it.fast4x.rimusic.utils.semiBold
import me.knighthat.Skeleton
import me.knighthat.colorPalette
import me.knighthat.component.tab.toolbar.InputDialog
import me.knighthat.typography

@ExperimentalMaterialApi
Expand Down Expand Up @@ -483,17 +484,48 @@ fun SliderSettingsEntry(
isEnabled: Boolean = true,
usePadding: Boolean = true
) = Column(modifier = modifier) {
val context = LocalContext.current
val manualEnterToggleState = rememberSaveable { mutableStateOf(false) }
val manualEnterInput = remember { mutableStateOf("%.1f".format(state).replace(",", ".")) }

val manualEnterDialog = remember {
object: InputDialog {
override val context = context
override val toggleState = manualEnterToggleState
override val iconId = -1 // Unused
override val titleId = R.string.enter_the_value
override val messageId = -1 // Unused
override val valueState = manualEnterInput

override fun onSet(newValue: String) {
val value: Float? = newValue.toFloatOrNull()
if (value != null) {
manualEnterInput.value = "%.1f".format(value).replace(",", ".")
onSlide(value)
onSlideComplete()
}
onDismiss()
}
}
}
manualEnterDialog.Render()

SettingsEntry(
title = title,
text = "$text (${toDisplay(state)})",
onClick = {},
onClick = {
manualEnterDialog.toggleState.value = true
},
isEnabled = isEnabled,
//usePadding = usePadding
)

Slider(
state = state,
setState = onSlide,
setState = { value: Float ->
manualEnterInput.value = "%.1f".format(value).replace(",", ".")
onSlide(value)
},
onSlideComplete = onSlideComplete,
range = range,
steps = steps,
Expand Down
1 change: 1 addition & 0 deletions composeApp/src/androidMain/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -777,4 +777,5 @@
<string name="removed_thumbnail">Removed Thumbnail</string>
<string name="failed_to_remove_thumbnail">Failed to Remove Thumbnail</string>
<string name="showsecondline">Show Translation in the Second Line</string>
<string name="enter_the_value">Enter The Value</string>
</resources>

0 comments on commit d19a27f

Please sign in to comment.