Skip to content

Commit

Permalink
IMprove demo for slider
Browse files Browse the repository at this point in the history
  • Loading branch information
alorma committed Jan 10, 2025
1 parent 67fb20a commit fc45c0b
Showing 1 changed file with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ fun SettingsScreen(
.padding(top = padding.calculateTopPadding()),
) {
val iconState = remember { mutableStateOf(false) }
SettingsGroupSectionSample(iconState.value)

SettingsSwitch(
state = iconState.value,
Expand Down Expand Up @@ -81,6 +80,7 @@ fun SettingsScreen(
SettingsMenuLinkSectionSample(iconState.value)
SettingsSliderSectionSample(iconState.value)
SettingsSelectorsSample(iconState.value)
SettingsGroupSectionSample(iconState.value)
}
}
}
Expand Down Expand Up @@ -198,20 +198,28 @@ private fun SettingsTriStateCheckboxSampleSection(showIcon: Boolean) {
@Composable
private fun SettingsSliderSectionSample(showIcon: Boolean) {
SampleSection(title = "SettingsSlider") {
val state = remember { mutableStateOf(5) }

SettingsSlider(
title = { Text(text = "Slider") },
value = state.value.toFloat(),
onValueChange = { state.value = it.toInt() },
subtitle = { Text(text = "Selected value: ${state.value}") },
icon = iconSampleOrNull(showIcon),
valueRange = 0f..20f,
steps = 20,
)
DemoSlider(showIcon)
}
}

@Composable
private fun DemoSlider(
showIcon: Boolean,
) {
val maxSteps = 6
val state = remember { mutableStateOf(maxSteps / 2) }

SettingsSlider(
title = { Text(text = "Slider") },
value = state.value.toFloat(),
onValueChange = { state.value = it.toInt() },
subtitle = { Text(text = "Selected value: ${state.value}") },
icon = iconSampleOrNull(showIcon),
valueRange = 0f..maxSteps.toFloat(),
steps = maxSteps - 1,
)
}

@Composable
private fun SettingsMenuLinkSectionSample(
showIcon: Boolean,
Expand Down Expand Up @@ -425,16 +433,7 @@ private fun SettingsGroupSectionSample(showIcon: Boolean) {
onClick = { state.value = !state.value },
)

val sliderState = remember { mutableStateOf(5) }
SettingsSlider(
title = { Text(text = "Slider") },
value = sliderState.value.toFloat(),
onValueChange = { sliderState.value = it.toInt() },
subtitle = { Text(text = "Selected value: ${sliderState.value}") },
icon = iconSampleOrNull(showIcon),
valueRange = 0f..20f,
steps = 20,
)
DemoSlider(showIcon)

val items = listOf(1, 2, 3)

Expand Down

0 comments on commit fc45c0b

Please sign in to comment.